当我尝试上传大小为16.9 MB的MP4视频时,使用ajax异步发布到PHP文件时,控制台会触发错误说明:POST http://website.com/proc_vids.php net :: ERR_EMPTY_RESPONSE
我知道这个问题与PHP memory_limit有关,因为当我设置为200 MB时,一切都很好,但当我将其更改回100 MB时,会发生此错误。
我甚至无法将POST发送到PHP变量,因为只要进行了ajax post调用,就会在服务器端(PHP)上执行任何操作时触发错误。 这是ajax邮政编码:
var proc = 1; video = document.getElementById('preview_video').src; $.ajax({ 'async': true, 'type': "POST", 'global': false, 'dataType': 'json', 'url': "proc_vids.php", 'data': {proc: proc, video: video} }).done(function () { //Do something });PHP代码:
$proc = $_POST['proc']; if ($proc == 1){ //$video = $_POST['video']; }正如您所看到的,我评论了将POST传递给变量但仍然触发错误的行。
我可以对包含base64代码的视频变量做些什么来不扩展消耗如此高的内存级别? 如果没有将memory_limit设置得更高,还有其他选择吗?
When I try to upload a MP4 video with 16.9 MB size, using ajax async post to an PHP file the console triggers an error saying: POST http://website.com/proc_vids.php net::ERR_EMPTY_RESPONSE
I know for a fact that this problem is related with PHP memory_limit because when I set to 200 MB it's all fine but when I change it back to 100 MB this error happens.
I can't even get the POST to an PHP variable because as soon as the ajax post call is made it triggers the error without even doing anything on server side (PHP). Here is the ajax post code:
var proc = 1; video = document.getElementById('preview_video').src; $.ajax({ 'async': true, 'type': "POST", 'global': false, 'dataType': 'json', 'url': "proc_vids.php", 'data': {proc: proc, video: video} }).done(function () { //Do something });PHP code:
$proc = $_POST['proc']; if ($proc == 1){ //$video = $_POST['video']; }As you can see I commented the line where I pass the POST to a variable and still triggering the error.
What can I do to the video variable containing the base64 code to not expand consuming such high memory levels? Is there any alternatives without setting the memory_limit higher?
最满意答案
由于cmorrissey问题解决了!
我使用了与此主题中描述的相同的方法: 将HTML5 Canvas转换为要上载的文件?
将AJAX POST作为FormData发送并将base64数据转换为Uint8Array为blob是在发出POST时不分配PHP内存的关键。 但要小心,因为较旧的浏览器可能不支持blob。
感谢你们 ;)
Problem solved thanks to cmorrissey!
I used the same method as described in this thread: Convert HTML5 Canvas into File to be uploaded?
Sending AJAX POST as a FormData and converting the base64 data to Uint8Array into a blob is the key to not allocate PHP memory when the POST is made. But be careful tho because older browsers may not support blob.
Thank you guys ;)
更多推荐
发布评论