Page 1 of 1

Form finishes submitting, but file doesn't reach destination

Posted: Thu Dec 31, 2009 2:19 am
by Dryan
I have a php form that I use to send a file to my ftp server. It's supposed to put the file into a folder named uploads. It finishes submitting, but when I check my ftp server, the file isn't there.

Here's the php:

<?php
if (($_FILES["file"]["size"] < 4000000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>




When it finishes submitting, it sends me to a page that correctly says this:

Upload: image.jpg
Type: image/jpeg
Size: 25.337890625 Kb
Temp file: /tmp/phpDoM7tw
Stored in: upload/image.jpg

Re: Form finishes submitting, but file doesn't reach destination

Posted: Thu Dec 31, 2009 2:42 am
by cpetercarter
Have you checked the permissions of your 'upload' directory? They will need to be set to 0777 in order that php can write the file there.

Re: Form finishes submitting, but file doesn't reach destination

Posted: Thu Dec 31, 2009 3:14 am
by Dryan
Well first I renamed the folder from uploads to upload because that was wrong. And I also changed the permissions from 755 to 777. But it's still not working.

Re: Form finishes submitting, but file doesn't reach destination

Posted: Thu Dec 31, 2009 6:37 am
by cpetercarter
It would be helpful to get some php error messages - could you put the following at the top of the script which is trying to move the uploaded file?

Code: Select all

error_reporting(E_ALL);
Also, check that you have the correct path from the script to the 'upload' directory. If the script is running as an 'include' within another script, the relevant path is the one from the parent script to 'upload', not from the included script.

Re: Form finishes submitting, but file doesn't reach destination

Posted: Thu Dec 31, 2009 10:18 am
by Dryan
After adding the error_reporting into it, this is the page it sends me to now:

Upload: yepw.jpg
Type: image/jpeg
Size: 52.6396484375 Kb
Temp file: /tmp/phpaD2omO

Warning: move_uploaded_file(upload/yepw.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /homepages/28/d93538065/htdocs/library2/upload_file.php on line 23

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpaD2omO' to 'upload/yepw.jpg' in /homepages/28/d93538065/htdocs/library2/upload_file.php on line 23
Stored in: upload/yepw.jpg

Re: Form finishes submitting, but file doesn't reach destination

Posted: Thu Dec 31, 2009 12:43 pm
by cpetercarter
You need to check that you have specified the path from upload_file.php to the 'upload' directory correctly.

Re: Form finishes submitting, but file doesn't reach destination

Posted: Thu Dec 31, 2009 1:30 pm
by Dryan
Ok, I uploaded the the form and .php to the root directory and it's working now.

Thanks!