在服务器端我正试图从其他网站传输文件,具有Ajax和实时能力,为了在用户获取url之后创建此功能我写了简单的ajax请求:
但是我的ajax无法在每次文件传输中提醒我作为实时响应,例如10% transfer
。
var url="fileTransfer.php";
$.ajax({
type: "POST",
url: urlFileTransfer,
data: {url: url},
success: function (fileTransfer) {
/* ALERT AFTER FILE TRANSFER */
}
});
fileTransfer.php
$path = 'newfile.zip';
$url = $_POST['url'];
$newfname = $path;
echo 'Starting Download!<br>';
$file = fopen($url, "rb");
if ($file) {
$newf = fopen($newfname, "wb");
if ($newf)
while (!feof($file)) {
fwrite($newf, fread($file, 1024 * 8), 1024 * 8);
echo '1 MB File Chunk Written!<br>';
}
}
if ($file) {
fclose($file);
}
if ($newf) {
fclose($newf);
}
echo 'Finished!';