我对AjaxForm Submit有一个奇怪的问题。我必须调试的项目应该使用Ajax将所选文件上传到服务器(PHP),以便可以跟踪上传进度。我确定我的php.ini允许POST和Upload大小为100+ MB,max_execution_time为5分钟。无论如何,如果我上传的文件少于9 MB(包括8.9 MB),则一切正常,文件已上传。 9 MB是“有时无法正常工作),并且10 MB以上的所有内容均会引起问题。 在下面的代码(简短版本)中,我将在引起问题的地方添加注释,请让我知道您的想法:
HTML(省略了进度条之类的东西以使代码易于阅读):
<form action="#" method="post" id="publisher-box-focus">
...controls for choosing a file etc....
<button type="button" onclick="Wo_GetPRecordLink()" id="publisher-
button"><span>Share</span></button>
<input type="hidden" name="hash_id" value="some_generated_id_is_here">
</form>
JS:
function Wo_GetPRecordLink() {
$('form.post').submit();
}
$('form.post').ajaxForm({
url: '<url>/myPhp.php',
beforeSend: function () {
var percentVal = '0%';
bar.width(percentVal);
percent.html(percentVal);
},
uploadProgress: function (event, position, total, percentComplete) { ***This works fine
var percentVal = percentComplete + '%';
bar.width(percentVal);
$('#progress').slideDown(200);
percent.html(percentVal);
},
success: function (data) {
if(data.status == 200) {
//My PHP does return 200 after file upload is complete but it gets incomplete POST
data thus sends no data response i'm expecting!
}
}
});
PHP:
<?php
$hash_id = '';
if (!empty($_POST['hash_id'])) {
$hash_id = $_POST['hash_id'];
}
echo "HASH IS: ".$hash_id; //*****HERE when uploading big files (and only files > 9MB
$hash_id is empty even thou Chrome Inspector shows that hidden input value is set
properly! This happens only for files bigger than 9 MB!
...
你们每个人都有这种问题吗?您有什么可能的原因吗?
服务器是ec2 Amazon实例。
PHP版本5.5.38
答案 0 :(得分:0)
如果服务器设置正确,则ajax post方法存在问题。
请不要忘记文件输入名称属性:)
你可以试试吗?
HTML:
<form action="#" method="post" id="publisher-box-focus">
...controls for choosing a file etc....
<input type="hidden" name="hash_id" value="some_generated_id_is_here">
<button type="button" onclick="Wo_GetPRecordLink(event)" id="publisher-button"><span>Share</span></button>
</form>
JS:
function Wo_GetPRecordLink(e) {
e.preventDefault();
$.ajax({
type: "POST",
url: '<url>/myPhp.php',
data: $('#publisher-box-focus').serialize(),
beforeSend: function () {
var percentVal = '0%';
bar.width(percentVal);
percent.html(percentVal);
},
uploadProgress: function (event, position, total, percentComplete) {
var percentVal = percentComplete + '%';
bar.width(percentVal);
$('#progress').slideDown(200);
percent.html(percentVal);
},
success: function (data) {
if (data.status == 200) {
}
}
});
}