Form finishes submitting, but file doesn't reach destination

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Dryan
Forum Newbie
Posts: 6
Joined: Thu Dec 31, 2009 2:13 am

Form finishes submitting, but file doesn't reach destination

Post 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
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

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

Post 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.
Dryan
Forum Newbie
Posts: 6
Joined: Thu Dec 31, 2009 2:13 am

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

Post 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.
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

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

Post 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.
Dryan
Forum Newbie
Posts: 6
Joined: Thu Dec 31, 2009 2:13 am

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

Post 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
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

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

Post by cpetercarter »

You need to check that you have specified the path from upload_file.php to the 'upload' directory correctly.
Dryan
Forum Newbie
Posts: 6
Joined: Thu Dec 31, 2009 2:13 am

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

Post by Dryan »

Ok, I uploaded the the form and .php to the root directory and it's working now.

Thanks!
Post Reply