当我尝试使用uploadify库在我的服务器上上传.zip文件时出错。
在我的uploadify.php中:
$fileTypes = array('jpg','jpeg','gif','png','JPG','JPEG','GIF','PNG','doc','docx','xls','xlsx','ppt','pptx','pdf','txt','zip','rar','DOC','DOCX','XLS','XLSX','PDF','PPT','PPTX','TXT','ZIP','RAR','csv','csvx','CSV','CSVX'); // File extensions
目标文件夹的权限为 777
我的脚本适用于所有其他扩展,只有.zip文件无法完成。 jquery动画显示上传栏达到100%,但随后变成红色并显示我的错误。
testtest.zip (118KB) - HTTP Error (403)
在我的控制台中,我收到了错误:
Failed to load resource: the server responded with a status of 403 (Forbidden)
使用.rar它会做同样的事情,所以我认为档案文件有问题,或者我需要做更多的事情。
完整的php文件:
$targetFolder = '/upload'; // Relative to the root
$uniqid = uniqid();
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
// Validate the file type
$fileTypes = array('jpg','jpeg','gif','png','JPG','JPEG','GIF','PNG','doc','docx','xls','xlsx','ppt','pptx','pdf','txt','zip','rar','DOC','DOCX','XLS','XLSX','PDF','PPT','PPTX','TXT','ZIP','RAR','csv','csvx','CSV','CSVX'); // File extensions
$fileParts = pathinfo($_FILES['Filedata']['name']);
$targetFile = rtrim($targetPath,'/') . '/' . $uniqid.'.'.$fileParts['extension'];
if (in_array($fileParts['extension'],$fileTypes)) {
move_uploaded_file($tempFile,$targetFile);
echo $uniqid.'.'.$fileParts['extension'];
} else {
echo 2;
}
}
完整的js文件:
$("#fileupload").uploadify({
'fileObjName' :'Filedata',
'auto' : true,
height : 30,
swf : 'uploadify/uploadify.swf',
uploader : 'uploadify/uploadify.php',
width : 120,
'onUploadSuccess' :function(file, data, response){
if(data == '2'){alert("fail");}
else{alert("ok");}
}
});