justlukeyou Posted October 25, 2012 Share Posted October 25, 2012 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"; ?> Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted October 25, 2012 Author Share Posted October 25, 2012 Sorted that bit, it uploads it to the folder the upload.php page is in. Can anyone advise how I change the storage location? Quote Link to comment Share on other sites More sharing options...
mikosiko Posted October 25, 2012 Share Posted October 25, 2012 (edited) Can anyone advise how I change the storage location? sure... what about if you read in the MANUAL the description and functionality of the function move_uploaded_file() ??? Edited October 25, 2012 by mikosiko Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted October 25, 2012 Author Share Posted October 25, 2012 Yes your right, I need to read through that. Can anyone suggest how I can make unique image name for each upload. That would be great. So it goes image1, image2, image3 etc $n = "image.$ext"; Quote Link to comment Share on other sites More sharing options...
kicken Posted October 25, 2012 Share Posted October 25, 2012 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. Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted October 26, 2012 Author Share Posted October 26, 2012 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.