Page 1 of 1

File Upload question, file doesn't show up on success

Posted: Wed Apr 04, 2007 11:25 pm
by jdhorton77
I know that subject line doesn't logically make since, but here's my situation. I have a file upload function that supposed to upload an image to a folder on the server called uploads. When I hit the submit button the process goes through like it should. But when I look in the folder, the image is not there. When I use the move_uploaded_file function, am I supposed to use an absolute address to the folder with http://somewhere.com/uploads/ ?

My http folder has the upload file along with the uploads folder. So I don't think I have to step out or anything. I appreciate all the help you guys give us newbs.

Code: Select all

if ($_FILES["file"]["error"] > 0)
{
     echo "Return Code: " . $_FILES["file"]["error"] . "<br />";	
}
     else
{
     $sql = "INSERT INTO images (imagenum, usernumber,imagename,category,public)
	values (null,'$usernumber','$imagename','$category','$public')";
					
	if (!mysql_query($sql,$connection)) {
	    die('Error: ' . mysql_error());
	}
	else {
	    $success = "Upload Successfull";

	    move_uploaded_file($_FILES["file"]["tmp_name"],
	    "uploads/" . mysql_insert_id());                                 // <---- question here 
	}
}

Posted: Wed Apr 04, 2007 11:53 pm
by feyd
PHP is not able to natively write files over HTTP requests without added help. Local paths are all you should require.

Posted: Thu Apr 05, 2007 12:02 am
by jdhorton77
So then it should be putting the image in the folder specified then right? If for some reason it couldn't see the folder, wouldn't it throw an error. Thanks for the help feyd

Posted: Thu Apr 05, 2007 12:06 am
by feyd
If it is unable to write to the location (for many reasons) it will throw an error.

Posted: Thu Apr 05, 2007 12:23 am
by jdhorton77
Well I know the folder is there. So I put it in an if statement and the function is returning false. Can you look at my statement and tell if I have it right?

Code: Select all

$iname = mysql_insert_id();
echo $iname;                        // I have this here just to make sure it wasn't null
				
if(!move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $iname)) { echo "failed"; }
       else { echo "success"; }

Posted: Thu Apr 05, 2007 12:28 am
by feyd
Are you sure PHP has the proper permissions to write files into that folder?

Posted: Thu Apr 05, 2007 12:35 am
by jdhorton77
Ahhh yeah, well, I was just about to say thanks for the help. And you can call me stupid now. I guess before you upload a file you should make sure it has permission to do so. Sorry guys. But one more question, it saved it as a binary file. Is that right even though it was a jpeg? Just wondering if I'll still be able to display on a page as a jpeg. Thanks again.

Posted: Thu Apr 05, 2007 5:28 am
by thiscatis
is it saved as a blob?
Then you can use get file content,
make sure to set the header right for that filetype.