简体   繁体   English

Move_uploaded_file($ _FILES ...)不起作用

[英]Move_uploaded_file ($_FILES…) Not working

The file is echoed correctly on the echo statement before 之前在echo语句中正确回显该文件

The uploaded file was to: images/smoker1.jpg and size was 10110 上传的文件是: images/smoker1.jpg ,大小是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. 当我使用FTP来检查目录images/文件中的文件smoker1.jpg不在那里。 Why ? 为什么? There are no errors coming from PHP when the upload button is pressed. 按下上传按钮时,PHP没有错误。

Any help in this appreciated. 任何帮助在此赞赏。

$_FILES['myfile']['name'] is the name of the file as it existed on the user's computer. $_FILES['myfile']['name']是用户计算机上存在的文件名。

It does not exist in this filename on your server. 它在您的服务器上的此文件名中不存在。 The uploaded file's actual name on your server is $_FILES['userfile']['tmp_name'] . 上传文件在服务器上的实际名称是$_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 ). 对于上传的文件, move_uploaded_file需要第一个参数( 字符串 文件名 )中的临时文件名。

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". 看起来您正在尝试将文件移动到名为“$ 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. 我无法分辨,因为你把它放在这里的代码会抛出一个错误,你在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. 所以我不确定move_uploaded_file里面的$ path周围的引号是否真的在你的真实代码中,或者只是你帖子中的拼写错误。

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. 如果不是,请确保您正在查看与此脚本所在目录相关的“images /”目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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