[英]PHP & jQuery file upload issues
I'm trying to use blueimp's jQuery file upload script . 我正在尝试使用blueimp的jQuery文件上传脚本 。
The files are sent to "upload.php": 文件发送到“ upload.php”:
if (isset($_FILES['file'])) {
$file = $_FILES['file'];
// Set variables
$file_name = stripslashes($file['name']);
if (!is_uploaded_file($file['name'])) {
echo '{"name":"'.$file_name.' is not a uploaded file."}';
exit;
}
}
.. but the script fails at is_uploaded_file despite passing isset($_FILES['file']). ..但尽管传递了isset($ _ FILES ['file']),但脚本在is_uploaded_file处失败。
What may be causing this? 是什么原因造成的?
EDIT: 编辑:
I changed from $file['name']
to $file['tmp_name']
and the is_uploaded_file
is passed. 我从
$file['name']
更改$file['tmp_name']
并传递了is_uploaded_file
。 Now the script fails at move_uploaded_file
: 现在,脚本在
move_uploaded_file
失败:
if (move_uploaded_file($file_name, $upload_dir."/".$file_name)) {
echo "success";
} else {
echo "failed";
}
You should use is_uploaded_file($file['tmp_name'])
. 您应该使用
is_uploaded_file($file['tmp_name'])
。 This is the actual filename on the server. 这是服务器上的实际文件名。
$file['name']
is the filename on the client's computer, which is only handy for renaming the file after it was uploaded. $file['name']
是客户端计算机上的文件名,仅在文件上传后方便重命名。
For more information, read the docs on is_uploaded_file()
: 有关更多信息,请阅读
is_uploaded_file()
上的文档:
For proper working, the function is_uploaded_file() needs an argument like $_FILES['userfile']['tmp_name'], - the name of the uploaded file on the client's machine $_FILES['userfile']['name'] does not work
为了正常工作,函数is_uploaded_file()需要一个类似$ _FILES ['userfile'] ['tmp_name']的参数-客户端计算机$ _FILES ['userfile'] ['name']上载文件的名称不行
Additionally, you said move_uploaded_file()
is not working as well. 此外,您说过
move_uploaded_file()
不能正常工作。 As expected, this is caused by the exact same problem : 不出所料,这是由完全相同的问题引起的:
You are trying to move the file $file_name
, but $file_name
is set to $file['name']
and not $file['tmp_name']
. 您正在尝试移动文件
$file_name
,但是$file_name
设置为$file['name']
而不是$file['tmp_name']
。 Please understand that $file['name']
contains only a string that equals the original filename on the computer, while $file['tmp_name']
contains a string pointing to a path on the server where the filename is not temporarily stored. 请理解,
$file['name']
仅包含等于计算机上原始文件名的字符串,而$file['tmp_name']
包含指向服务器上未临时存储文件名的路径的字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.