简体   繁体   中英

Move_uploaded_file ($_FILES…) Not working

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.

$_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.

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);

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM