我正在通过 PHP、ajax 中的 URL 上传文件。我需要一个进度条来显示已上传了多少文件。
请查看我在代码中使用的内容。
PHP 代码
$upload_url = $_REQUEST['upload_url'];
$arr_upload_file = explode("/",$upload_url);
$ext = $arr_upload_file[count($arr_upload_file)-1];
$file = md5(mt_rand(0,1000) . implode(getdate()) . $ext) . '-' . $ext;
//echo $_SERVER[']
$app->sessions->get_var('folder_id');
$path = 'C:/wamp/www/bigoshare/uploads/';
$uploadss = file_put_contents($path.$file,file_get_contents($upload_url));
$size = getimagesize($path.$file);
$totsize = strlen(file_get_contents($upload_url));
阿贾克斯代码
$('#url_upload_btn').live('click', function () {
$('#progress_container').fadeIn(100); //fade in progress bar
$('#progress_bar').width("50%"); //set width of progress bar based on the $status value (set at the top of this page)
$('#progress_completed').html("50%");
upload_url = $('#txt_url_link').val();
setInterval("getinterdata()", 1000);
var dataString = 'upload_url=' + upload_url;
$.ajax({
url: App.url + '/allusers/uploadbyurl/',
type: 'GET',
data: dataString,
success: function (data) {
$('#uploads').prepend($.trim(data));
$('.show_url_Upload_div').hide();
}
});
});
function getinterdata() {
$.ajax({
url: App.url + '/allusers/getuploadpercentage/',
type: 'GET',
success: function (data) {
console.log(data);
}
});
}
当我执行上面的代码时,第二个 ajax 仅在文件完成上传后才响应,而我在上传和进行中需要。