I'm trying to use blueimp's jQuery file upload script.
The files are sent to "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']).
What may be causing this?
EDIT:
I changed from $file['name'] to $file['tmp_name'] and the is_uploaded_file is passed. Now the script fails at 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']). 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.For more information, read the docs on
is_uploaded_file():Additionally, you said
move_uploaded_file()is not working as well. As expected, this is caused by the exact same problem:You are trying to move the file
$file_name, but$file_nameis set to$file['name']and not$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.