0

The file is echoed correctly on the echo statement before

The uploaded file was to: images/smoker1.jpg and size was 10110

Here's the code:

if ( $_POST['upLoad']){

   $path= "images/".$_FILES['myfile']['name'];

   $echo "The uploaded file was to: $path  and size was ".$_FILES['myfile']['size'] ;

      move_uploaded_file($_FILES['myfile']['name'],"$path");


$F =$_SESSION['currentPage']; //load current page again

}

When I use FTP to check for the file in the directory images/ the file smoker1.jpg is not there. Why ? There are no errors coming from PHP when the upload button is pressed.

Any help in this appreciated.

5
  • 1
    show your form tag and print_r($_FILES) Commented Apr 10, 2014 at 2:31
  • 1
    RTM Commented Apr 10, 2014 at 2:43
  • Turn error reporting on Commented Apr 10, 2014 at 2:51
  • Array ( [myfile] => Array ( [name] => smoker1.jpg [type] => image/jpeg [tmp_name] => /tmp/phptR4ckK [error] => 0 [size] => 10110 ) ) Commented Apr 10, 2014 at 3:41
  • The above shows the print_r($_FILES) does that help anybody...thanks John, Fred ad Ben for you help...no errors reported...any help appreciated...thanks Commented Apr 10, 2014 at 3:43

3 Answers 3

1

$_FILES['myfile']['name'] is the name of the file as it existed on the user's computer.

It does not exist in this filename on your server. The uploaded file's actual name on your server is $_FILES['userfile']['tmp_name']. That's the file you need to be working with.

Sign up to request clarification or add additional context in comments.

Comments

1

For uploaded files, move_uploaded_file needs of a temporary file name in the first parameter (string filename).

Change from:

move_uploaded_file($_FILES['myfile']['name'],"$path");

To:

move_uploaded_file($_FILES['myfile']['tmp_name'], $path);

2 Comments

Thanks QUod, the problem is all fixed...fancy that the file is uploadedwith a tmp_name, and this was not noticedby me, or written in the tutorials...thanks a lot for all the guys who helped and the quick response too! Enjoy your PHP programming.!!!!
It's most certainly written in the tutorials. None of them would work without it. php.net/manual/en/features.file-upload.post-method.php for example.
0

It looks like you are trying to move the file to a folder called "$path".

I can't tell since the code as you've put it here would throw an error, you've got a $ in front of echo. So I'm not sure if the quotes around $path inside move_uploaded_file is actually in your real code or that's just a typo in your post.

But if it is, try removing the quotes around that variable.

If it isn't, make sure you are looking at the "images/" directory that is relative to the directory this script is in.

2 Comments

"$path" might seem silly but it would result in the same as $path alone
Thanks Matt problem resolved, the tutorials didn't tell me about the tmp_name during uploading...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.