PHP Ajax XMLHttpRequest popen live progress
我正在尝试现场输出:ffmpeg进度 当我单独执行php文件时效果非常好:许多行中的文本一行接一行出现 ••但当它是XMLHttpRequest上下文时,输出为1行空 PHP在不使用AJAX的情况下工作:PHP Ajax XMLHttpRequest popen live progress,php,ajax,ffmpeg,xmlhttprequest,popen,Php,Ajax,Ffmpeg,Xmlhttprequest,Popen,我正在尝试现场输出:ffmpeg进度 当我单独执行php文件时效果非常好:许多行中的文本一行接一行出现 ••但当它是XMLHttpRequest上下文时,输出为1行空 PHP在不使用AJAX的情况下工作: ini_set("output_buffering", "0"); ob_implicit_flush(true); $call_mp4 = ' __FFMPEG Command HERE__ '; $proc = popen($call_mp4, 'r'); while (!feof($pr
ini_set("output_buffering", "0");
ob_implicit_flush(true);
$call_mp4 = ' __FFMPEG Command HERE__ ';
$proc = popen($call_mp4, 'r');
while (!feof($proc)) {
echo '['.date("i:s")."] ".fread($proc, 4096).'<br>';ob_flush();flush();
}
ini_集(“输出缓冲”,“0”);
ob_隐式_刷新(真);
$call_mp4='uuu FFMPEG命令在此处\uuuuuu';
$proc=popen($call_mp4,'r');
而(!feof($proc)){
echo“[”.date(“i:s”)。“]”。fread($proc,4096)。“
”;ob_flush();flush();
}
有人知道为什么在AJAX中它是空白的,只有一行吗?
如何解决这个问题
关于我有一个“变通”的临时解决方案
//JS FILE
var formData = new FormData();
var fileSizeForAllUpload = 0;
var allAllowedExt_arr = __EXTENSIONS ALLOWED HERE__;
// Retrieve the FileList object from the referenced element ID (for multiple uploading files)
var ins = document.getElementById( jXHRinputID ).files.length;
for (var x = 0; x < ins; x++) {
fileName = ''; fileExtension = '';
fileName = document.getElementById( jXHRinputID ).files[x].name ;
fileSize = document.getElementById( jXHRinputID ).files[x].size ; jLog('• fileName -> ' + fileName + ' : fileSize -> ' + fileSize);
fileExtension = fileName.substr((fileName.lastIndexOf('.') + 1));
if ( !in_array( fileExtension , allAllowedExt_arr ) ){ fileExtension = 'notAllowed'; }
// if file too large...
if ( fileSize < 400000000 ) {
formData.append( jXHRinputID+"[]", document.getElementById( jXHRinputID ).files[x]);
fileSizeForAllUpload = fileSizeForAllUpload + fileSize;
}
if ( fileSize >= 400000000 ) { fileName = fileName + ' ' + _file_size_too_large ; }
$('#uploadingFilesNames_'+jXHRinputID).append( '• <img src="'+subdomain_icons+'/files/'+ fileExtension +'.png" width="42px" />' + fileName + '<br>' );
}
if ( fileSizeForAllUpload > 0 ) {
xhr = new XMLHttpRequest();
xhr.open('POST', '___WEB PATH OF THE PHP FILE___'+"?"+params, true);
xhr.upload.addEventListener("loadstart", function(e){
console.log('loadstart');
}, false);
// upload progress
xhr.upload.addEventListener("progress", function(e){
if(e.lengthComputable){
var percentage = Math.round((e.loaded * 100) / e.total);
$("#percentageCalc_"+jXHRinputID).html(percentage + '%');
$("#progressBar_"+jXHRinputID).val(percentage);
}
}, false);
xhr.upload.addEventListener("load", function(e){
console.log('transferCompleteFunction');
}, false);
xhr.onprogress = function(e) {
console.log('onprogress');
// ******** HERE : it's the actual line that output live from the echo stuff;ob_flush();flush();
$('#liveXHRoutput_'+jXHRinputID).html(e.currentTarget.responseText);
}
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
console.log('Complete');
}
}
xhr.send(formData);
}
它的工作非常好,除了长视频
是否有人(非常了解FFMEG)知道更好的检查方法我有一个“变通”的临时解决方案
//JS FILE
var formData = new FormData();
var fileSizeForAllUpload = 0;
var allAllowedExt_arr = __EXTENSIONS ALLOWED HERE__;
// Retrieve the FileList object from the referenced element ID (for multiple uploading files)
var ins = document.getElementById( jXHRinputID ).files.length;
for (var x = 0; x < ins; x++) {
fileName = ''; fileExtension = '';
fileName = document.getElementById( jXHRinputID ).files[x].name ;
fileSize = document.getElementById( jXHRinputID ).files[x].size ; jLog('• fileName -> ' + fileName + ' : fileSize -> ' + fileSize);
fileExtension = fileName.substr((fileName.lastIndexOf('.') + 1));
if ( !in_array( fileExtension , allAllowedExt_arr ) ){ fileExtension = 'notAllowed'; }
// if file too large...
if ( fileSize < 400000000 ) {
formData.append( jXHRinputID+"[]", document.getElementById( jXHRinputID ).files[x]);
fileSizeForAllUpload = fileSizeForAllUpload + fileSize;
}
if ( fileSize >= 400000000 ) { fileName = fileName + ' ' + _file_size_too_large ; }
$('#uploadingFilesNames_'+jXHRinputID).append( '• <img src="'+subdomain_icons+'/files/'+ fileExtension +'.png" width="42px" />' + fileName + '<br>' );
}
if ( fileSizeForAllUpload > 0 ) {
xhr = new XMLHttpRequest();
xhr.open('POST', '___WEB PATH OF THE PHP FILE___'+"?"+params, true);
xhr.upload.addEventListener("loadstart", function(e){
console.log('loadstart');
}, false);
// upload progress
xhr.upload.addEventListener("progress", function(e){
if(e.lengthComputable){
var percentage = Math.round((e.loaded * 100) / e.total);
$("#percentageCalc_"+jXHRinputID).html(percentage + '%');
$("#progressBar_"+jXHRinputID).val(percentage);
}
}, false);
xhr.upload.addEventListener("load", function(e){
console.log('transferCompleteFunction');
}, false);
xhr.onprogress = function(e) {
console.log('onprogress');
// ******** HERE : it's the actual line that output live from the echo stuff;ob_flush();flush();
$('#liveXHRoutput_'+jXHRinputID).html(e.currentTarget.responseText);
}
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
console.log('Complete');
}
}
xhr.send(formData);
}
它的工作非常好,除了长视频
是否有人(非常了解FFMEG)更了解chec