cancel
Showing results for 
Search instead for 
Did you mean: 

Where do PHP uploaded images go to

SoulBriski
Grafter
Posts: 179
Registered: ‎15-06-2007

Where do PHP uploaded images go to

Hi
when using php script to handle uploaded images, where do the images go?
I am trying to give my site visitors the option to submit images so i have created a simple form that submits the selected image to an 'upload.php' script
in the script, i've set the destination directory to "uploads/" and used the following code to check the uploaded file
if (is_uploaded_file($_FILES['imagefile']['tmp_name']))

This line of code always returns true but the image is nowhere to be found!
Where has it gone?
any answers would be greatly appreciated
Thanks
4 REPLIES 4
MikeWhitehead
Grafter
Posts: 748
Registered: ‎19-08-2007

Re: Where do PHP uploaded images go to

Have you read this?
I'd help more but, for now, my cat has decided the keyboard is a good place to lie down (needed to push her about to type this message!)  Undecided
SoulBriski
Grafter
Posts: 179
Registered: ‎15-06-2007

Re: Where do PHP uploaded images go to

thanks for your help mike
in the short time since i posted this i have found the simplest of solutions.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>
<body>
<form name="form1" method="post" action="" enctype="multipart/form-data">
<input type="file" name="imagefile">
<br>
<input type="submit" name="Submit" value="Submit">

<?php
if(isset( $Submit )) {
//If the Submitbutton was pressed do:

if ($_FILES['imagefile']['type'] == "image/gif"){
copy ($_FILES['imagefile']['tmp_name'], "uploads/".$_FILES['imagefile']['name'])
or die ("Could not copy");
echo ""; 
        echo "Name: ".$_FILES['imagefile']['name'].""; 
        echo "Size: ".$_FILES['imagefile']['size'].""; 
        echo "Type: ".$_FILES['imagefile']['type'].""; 
        echo "Copy Done...."; 
    } else {
        echo "<br><br>";
        echo "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br>";
    }
}
?>
</form>
</body>
</html>

this is rough but it works perfectly well and it couldn't be easier.
it's almost to easy to be true
Peter_Vaughan
Grafter
Posts: 14,469
Registered: ‎30-07-2007

Re: Where do PHP uploaded images go to

Actually that's hard. Just use move_uploaded_file()
Files are uploaded as temporary files to the servers /tmp directory from where you can move them to your local (server) storage using move_uploaded_file(). See the php.net website for how to use it.
SoulBriski
Grafter
Posts: 179
Registered: ‎15-06-2007

Re: Where do PHP uploaded images go to

Thanks Peter
I understand the move_uploaded_file() function a bit better now and it seems to be working.
This function suits me better anyway because stage 2 of my process is me moving the images to their new permanent location.
Users upload their images to the temp directory and they stay there until i have vetted them. I then use this function again to upload them to the gallery