Jump to content

Help understanding how to do a file upload | Team Bio List


Recommended Posts

Hello again:

 

I would like to see if someone can either show me some code, or point me in the direction of a good article about uploading a file (meaning a photo, .JPG, .GIF, etc) via PHP. I have only done this with ASP.

 

My searches on GOOGLE are only showing me ways to upload a file INTO the database, and I don't believe that is the proper way to do it.

 

I have always stored the file (.JPG) in a folder called "uploads" and stored the file name (myPhoto.JPG) in the database.

 

So, if I want to make a Team bio list with a photo, a title, and a description what is the proper way to do that?

 

Meaning, I click "Add Player" and a form with title, description, and a photo upload field appear. The data is filled out, "Submit" is clicked, and the photo is uploaded to "uploads" and all other data is inserted into the database.

 

I had wanted to be able to modify, delete, or make inactive each player, and use a dropdown SELECT menu to choose what player to edit.

 

Any ideas how to accomplish this?

 

I would appreciate the help!

Gonna break this down for you.

 

make a form

form hits an upload script

the file type is checked,max size, name sanitized, and unique timestamp also added to the name of the file.

You can make a folder lets say images

that will be the path to the image

you append the image path to the filename, path/filename

save these results into a field in a database

you place your uploaded file into that folder

You could also add additional information to the database for each mage, like who uploaded it, the current date, what type it is, it's size,etc...

 

 

If all went well you now have a database that can call to that knows where the exact location is for image.

 

Call to mysql with select statements in whatever way you wish to display them

 

Hi:

 

Thanks for the reply.

 

Do you have an example of this, or can you point me to one online?

 

I do like the appending Time/DateStamp to images so one never overwrites a file of the same name.

 

I have done all of this with ASP programming, but I am trying to learn how to do it with PHP haven't found an example of this format online. I keep finding ones the insert the file into the database.

 

Thanks.

Yeah I tried out the above tutorial, one of the few that actually works, but needs quite a few changes.

 

I made a function to add a timestamp to a file name whether it be in a folder or the single file.

 

<?php
function addTimestamp($filename) {
$character = "/";
$target_check = strrchr($filename,$character);
    if ($target_check[$character]) {
     $temp_filename1 = end(explode($target_check[$character],$filename));
     $target = true;
     } else {
      $temp_filename1 = $filename;
      }   
$temp_filename = strtolower(trim($temp_filename1));
$timestamp = date('Y-m-d-H-i-s');//this one more readable
//$timestamp = time();//or uncheck this and use time
if ($target) {
$new_filename = str_replace($temp_filename1, "$timestamp-$temp_filename", $filename);
} else {
$new_filename = "$timestamp-$temp_filename";
}
return $new_filename;
}
?>

<?php
//some example files
$file1 = "images/SomeCoolPic.png";
$file2 = "http://mysite.com/path/my-cat.jpg";
$file3 = "pictures-of-flowers.jpg";
$file4 = "thumbnails.png";
$file5 = "PEOPLE.png";

//this will just add the timestamp wherever you call for it
$file1 = addTimestamp($file1);
$file2 = addTimestamp($file2);
$file3 = addTimestamp($file3);
$file4 = addTimestamp($file4);
$file5 = addTimestamp($file5);

//gonna echo to see the new file names
echo $file1,"<br />";
echo $file2,"<br />";
echo $file3,"<br />";
echo $file4,"<br />";
echo $file5,"<br />";

?>

 

The results look similar to this

 

images/2011-01-28-02-14-22-somecoolpic.png

http://mysite.com/path/2011-01-28-02-14-22-my-cat.jpg

2011-01-28-02-14-22-pictures-of-flowers.jpg

2011-01-28-02-14-22-thumbnails.png

2011-01-28-02-14-22-people.png

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.