我正在使用ajax发送一个文件到PHP文件。一切都很好,除了尺寸。
jquery:
<script>
$('#submitshout').click(function () {
$('.shoutinputhover').show();
var formDatashout = new FormData($('#shoutform')[0]);
$.ajax({
url: "../pages/sn/ajax/submitshout.php",
type: "POST",
data: formDatashout,
success: function (msg) {
alert(msg);
if (msg == 'update') {
addshout();
}
},
cache: false,
contentType: false,
processData: false
});
});
</script>
HTML: <form method="post" enctype="multipart/form-data" id="shoutform" >
<textarea class="ordinaryinput" style="width: 100%;height: 60px" id="shouttxtarea" name="shouttxtarea"></textarea>
<div class="shoutaddimage">
<input type="file" name="shoutaddimageer" id="shoutaddimageer" style="width: 100%" >
</div>
</form>
和PHP文件:
session_start();
error_reporting(E_ERROR);
header('Content-Type: text/plain; charset=utf-8');
require '../../../elements/config.php' ;
// get image
die($_FILES["shoutaddimageer"]["size"]);
如果我在上面的php代码中放置name或type而不是size,它将准确地返回文件类型或文件名,但它不能与size一起工作,它什么也不返回!!!!
既然我可以得到文件类型和文件名,这意味着发送表单是正常的。但是尺寸有什么问题?
如果你的文件上传由于任何原因被中止,那么没有大小。
检查返回值:$_FILES['shoutaddimageer']['error']
以下是错误列表:http://php.net/manual/en/features.file-upload.errors.php