Jump to content

PHP Picture upload modifcation help


pleek

Recommended Posts

What i have

Ok so i have a code that uploads images to a dir on my server. The script works great but i want to modify it. The script shows all the pictures in the "images" dir that have been uploaded. Here is the script working on my server

 

What i want to do

The current code actually shows all the images that have been uploaded. I would like it to just show the link to the one you just uploaded. I know its possible but i have no clue how to do it. Any ideas?

 

Heres the script that shows the photos in the "images" dir:

 

list_images.php

 

<?
$handle = @opendir("images");

if(!empty($handle))
{
while(false !== ($file = readdir($handle)))
{
if(is_file("images/" . $file))
echo '<img src="images/' . $file . '"><br><br>';
}
}

closedir($handle);
?>

 

There are two other php files also, upload.php and upload_form.php

Link to comment
Share on other sites

"I would like it to just show the link to the one you just uploaded."

 

just echo the URL for the uploaded files, don't echo the contents of the directory. if you upload a file called someimage.jpg, then echo a a link to that image:

 

echo "<IMG SRC='/path/to/images/someimage.jpg'>";

Link to comment
Share on other sites

but with that i have to know the exact name of the uploaded file. Can i use a variable to have it work with what ever the file uploaded is named? So that the url of the picture will print onscreen. After uploading an image?

Link to comment
Share on other sites

when a file is uploaded, you have to name it, therefore you will always know the name of the file. there is no function to "show what the recent person uploaded via this script."

 

logic:

 

for each uploaded image, store the name of the image, then echo a link for each uploaded image using the stored image names.

Link to comment
Share on other sites

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.