View Full Version : PHP file upload system, need help customizing it

02-26-2008, 10:58 PM
I am fairly new to PHP scripting and have come across a little problem. I am creating a file upload system so users can upload there owns photo's. I have got the following script but i need help in customizing it to fit my needs



// Where the file is going to be placed
$target_path = "uploads/";

/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";

<br /><br />
<a href="photogallery.php">Click Here to View Your Photo</a>


$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

$pfile = fopen("userpics.htm","a+");

// If everything is OK -> store user data

fwrite($pfile, "\n<embed src = \"$target_path\" /><p>");

photos.php (where the user sees the uploaded photo)


I need help to define how the image will look. I need to know how i can get the php code to add a CSS style to the photo and if possible for it to use the lightbox javascript action. The lightbox isn't exactly essential as long as i can link to a full size image but it would be nice. Also the CSS script would shrink the photo for the thumbnail. I just need to link to a full size image.

I hope that you can understand this and that you can help me out cos it is really getting on my nerves now. I have tried everything i can think of


02-27-2008, 03:58 PM
You should upload both a fullsize and a thumbnail image,
along with a caption. Those would be selected in a form.

Right after you upload your photo to a directory,
append a line to a text file that has the photo filename and caption.
It can also have some sort of ID, like a timestamp (for sorting or future editing).

That text file called "gallery.txt" might look something like this:

12341241|myphoto1.jpg|myphoto1_thumbnail.jpg|This is my first photo
34235254|myphoto2.jpg|myphoto2_thumbnail.jpg|My Vacation photo

Now, the script that generates the images can open that
text file and read each line one by one ... it then generates
the HTML to do whatever you want with the image.

PHP script that displays gallery:

#Read File List
$fp = fopen($database, "r");
$array1 = explode("\n", fread($fp, filesize($database)));
fclose ($fp);
sort($array1);# rsort=reverse sort

$count = count($array1);
for($i = 0; $i < $count; $i++) {
list ($id, $photo, $full, $thumb, $caption) = split ('\|', $array1[$i]);

// Now you echo the HTML, and it could be Lightbox code too ...
<a href='$full'><img src='$thumb' alt='' /></a>