【发布时间】:2020-11-24 01:55:05
【问题描述】:
我对 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
【问题讨论】:
-
您缺少方法类型。 $("#theForm").ajaxForm({url: 'server.php', type: 'post'})
-
嗯没有帮助:(
-
在本地环境中一切正常吗?
-
hmmm 我只在网站上部署了这个版本,因为它是一个复杂的系统,我只是要“修复一些错误”
标签: javascript php ajaxform