我想创建一个上传脚本。这是我的 JS:
$("#subUpload").live("change", function(){
var fd = new FormData();
var file = this.files[0];
fd.append("subUpload", file);
$.ajax({
type: 'POST',
cache: false,
url: "script.php",
processData: false,
contentType: false,
data: fd,
success: function(data){
alert("Message: " + data);
}
});
});
这是我的PHP:
<?php
if($_FILES['subUpload']['error'] == 0){
if(is_dir('./files')){
if(move_uploaded_file($_FILES['subUpload']['tmp_name'], '/files/'.$_FILES['subUpload']['tmp_name'])){
echo"UPLOADED";
}else{
echo"FAIL";
}
}
else{
echo "Uncorrect Path";
}
}
else{
echo $_FILES['subUpload']['error'];
}
?>
我总是收到“失败”的消息。我已将文件夹权限设置为 777。有什么想法吗?