Jump to content

Image Stored Location


justlukeyou

Recommended Posts

Hi,

 

I have copied the following code from a book. It displays the image but I have no idea where the temporary file and permanent file is stored.

 

Any suggestions on how I can determine where the image is stored.

 

 

<?php // upload.php
echo <<<_END
<form method='post' action='upload.php' enctype='multipart/form-data'>
Select a JPG, GIF, PND or TIF File
<input type='file' name='filename' size='20' />
<input type='submit' value='Upload' />
</form>
_END;


if ($_FILES)
{
$name = $_FILES['filename']['name'];

switch($_FILES['filename']['type'])
{
case 'image/jpeg': $ext = 'jpg'; break;
case 'image/gif': $ext = 'gif'; break;
case 'image/png': $ext = 'png'; break;
case 'image/tiff': $ext = 'tif'; break;
default:   $ext = ''; break;
}
if ($ext)
{
$n = "image.$ext";
move_uploaded_file($_FILES['filename']['tmp_name'], $n);
echo "Upload image '$name' as '$n':<br />";
echo "<img src='$n' />";
}
else echo "'$name' is not accepted image file";
}
else echo "No image has been uploaded";
?>

Link to comment
Share on other sites

Rather than number them 1, 2, 3, etc just generate a unique string. Either using the current time value, or something like uniqid. If you want to make sure the generated name doesn't exist, keep generating a new name in a loop so long as file_exists returns true.

 

Thats what I was looking for! Cheers dude. That sounds much better.

 

Then I take it all I need to do is to add the random number (123456.png) into a column under the members profile. Then I can echo just the number into the image tag from the database.

 

Cheers dude.

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.