上载有关问题,小文件上载正常,上载大于100M的文件,进度条到100M以外的时候,进度条就不走了,代码什么地方出有关问题了

php中文网
发布: 2016-06-13 11:05:49
原创
904人浏览过

下载问题,小文件下载正常,下载大于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) #  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 以上

你的下载代码不具有断点续传能力,一旦出现传输错误,即可终止
------解决方案--------------------
我该写了一下,你看看
<br>Function down($file){<br>    IF(!$file Or !File_Exists($file) Or !Is_Readable($file)) {Return False;}<br><br>    IF($f = atr($file)) {<br>        Header("Content-Length:{$f['size']}");<br>        Header('Content-Description:File Transfer');<br>        Header('Content-Transfer-Encoding:binary');<br>        Header('Expires:0');<br>        Header('Cache-Control:must-revalidate');<br>        Header('Pragma:public');<br> <br>        IF(Function_exists("mime_content_type")) {<br>            Header("Content-Type: ".mime_content_type($f['name']));<br>        }Else{<br>            Header("Content-Type: application/octet-stream");<div class="clear"></div>
登录后复制
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号