上傳有關問題,小檔案上傳正常,上傳大於100M的檔案,進度條到100M以外的時候,進度條就不走了,代碼什麼地方出有關問題了

來源:互聯網
上載者:User
下載問題,小檔案下載正常,下載大於100M的檔案,進度條到100M以外的時候,進度條就不走了,代碼什麼地方出問題了?
本帖最後由 bxline 於 2012-12-17 06:31:43 編輯

我用的是下面的代碼,我實驗了兩回一次下載到145M不走了,一次下載到129M就不走了
,這是怎麼回事?小檔案下載正常,就是大於100M的檔案不正常
下面是代碼:我是03+FASTCGI,不是apache,所以代碼中有的行給注釋掉了

if(file_exists($filename)){
$mtime = ($mtime = filemtime($filename)) ? $mtime : gmtime();
$size = intval(sprintf("%u", filesize($filename)));
#if (intval($size + 1) > return_bytes(ini_get('memory_limit')) && intval($size * 1.5) <= 1073741824) {
# ini_set('memory_limit', intval($size * 1.5));
#}
[email protected]_setenv('no-gzip', 1);
[email protected]_set('zlib.output_compression', 0);
header('Content-Description: File Transfer');
header('Content-Type: application/force-download');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($filename));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header("Content-Length: " . $size);
set_time_limit(300);
$chunksize = 1 * (1024 * 1024);
// ob_clean();
// flush();
if ($size > $chunksize) {
$handle = fopen($filename, 'rb');
$buffer = '';
while (!feof($handle)) {
$buffer = fread($handle, $chunksize);
echo $buffer;
ob_flush();
flush();
}
fclose($handle);
} else {
ob_flush();
flush();
readfile($filename);
}
exit;
}
------解決方案--------------------
echo 100 * 1024 / 300;
得 341 K/s
即需要平均頻寬為 3M 以上

你的下載代碼不具有斷點續傳能力,一旦出現傳輸錯誤,即可終止
------解決方案--------------------
我該寫了一下,你看看

Function down($file){
IF(!$file Or !File_Exists($file) Or !Is_Readable($file)) {Return False;}

IF($f = atr($file)) {
Header("Content-Length:{$f['size']}");
Header('Content-Description:File Transfer');
Header('Content-Transfer-Encoding:binary');
Header('Expires:0');
Header('Cache-Control:must-revalidate');
Header('Pragma:public');

IF(Function_exists("mime_content_type")) {
Header("Content-Type: ".mime_content_type($f['name']));
}Else{
Header("Content-Type: application/octet-stream");
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.