所以我尝试在我的网站中使用Fine-uploader (Minimal jQuery Demo) 将一些图片上传到网络服务器上传文件夹。但是上传总是失败,我不知道为什么。
当我单击“上传文件”并选择一个文件时,它开始上传(进度条开始填充),当它达到 100% 时,它显示“上传失败”并在检查元素中给出此错误:( 更大尺寸的图像)
这是upload.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Fine Uploader - jQuery Wrapper Minimal Demo</title>
<link href="css/fineuploader-3.6.3.css" rel="stylesheet">
</head>
<body>
<div id="fine-uploader"></div>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="js/jquery.fineuploader-3.6.3.js"></script>
<script>
function createUploader() {
var uploader = new qq.FineUploader({
element: document.getElementById('fine-uploader'),
request: {
endpoint: 'upload_file.php'
}
});
}
window.onload = createUploader;
</script>
</body>
</html>
和upload_file.php:
<?php
for($i=0; $i<count($_FILES['file']['type']); $i++) {
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"][$i]);
$extension = end($temp);
if ((($_FILES["file"]["type"][$i] == "image/gif")
|| ($_FILES["file"]["type"][$i] == "image/jpeg")
|| ($_FILES["file"]["type"][$i] == "image/jpg")
|| ($_FILES["file"]["type"][$i] == "image/pjpeg")
|| ($_FILES["file"]["type"][$i] == "image/x-png")
|| ($_FILES["file"]["type"][$i] == "image/png"))
&& ($_FILES["file"]["size"][$i] < 50000000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"][$i] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"][$i] . "<br>";
}
else
{
echo "Upload: " . $_FILES["file"]["name"][$i] . "<br>";
echo "Type: " . $_FILES["file"]["type"][$i] . "<br>";
echo "Size: " . ($_FILES["file"]["size"][$i] / 1024) . " kB<br>";
echo "Temp file: " . $_FILES["file"]["tmp_name"][$i] . "<br>";
if (file_exists("upload\\" . $_FILES["file"]["name"][$i]))
{
echo $_FILES["file"]["name"][$i] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"][$i],
"\\upload\\" . $_FILES["file"]["name"][$i]);
echo "Stored in: " . "upload\\" . $_FILES["file"]["name"][$i];
}
}
}
else
{
echo "Invalid file";
}
}
?>