douzhuan1467
2016-01-10 12:32
浏览 108
已采纳

使用readfile()无法下载大文件

I have the following code to force download an IPA file (after codesigning it with a script). It works fine with smaller files but with larger files, my web server starts returning a 500 Internal Server Error. Would someone be able to help me tweak my existing code to overcome this issue?

$time = md5(time());

// Runs code signing script here
// And then attempts to initiate download

$path = "done/$time/";         
$latest_ctime = 0;
$latest_filename = '';    

$d = dir($path);
while (false !== ($entry = $d->read())) {
  $filepath = "{$path}/{$entry}";
  if (is_file($filepath) && filectime($filepath) > $latest_ctime) {
    $latest_ctime = filectime($filepath);
    $latest_filename = $entry;
  }
}        

 header("Cache-Control: public");
 header("Content-Description: File Transfer");
 header("Content-Disposition: attachment; filename=$time.ipa");
 header("Content-Type: application/ipa");
 header("Content-Transfer-Encoding: binary");
 // Read the file from disk
 readfile("done/$time/".$latest_filename);
       // header('location: dashboard.php');
   } else {
// Throwback

die("Failed. Contact support. // <p>$sign</p>");

}

图片转代码服务由CSDN问答提供 功能建议

我有以下代码强制下载IPA文件(在用脚本对其进行编码后)。 它适用于较小的文件,但文件较大,我的Web服务器开始返回500内部服务器错误。 有人能够帮助我调整现有代码来克服这个问题吗?

  $ time = md5(time()); 
 
 //在此处运行代码签名脚本
 //然后尝试启动下载
 
 $  path =“done / $ time /”;  
 $ latest_ctime = 0; 
 $ latest_filename ='';  
 
 $ d = dir($ path); 
while(false!==($ entry = $ d-&gt; read())){
 $ filepath =“{$ path} / {$ entry}  “; 
 if(is_file($ filepath)&amp;&amp; filectime($ filepath)&gt; $ latest_ctime){
 $ latest_ctime = filectime($ filepath); 
 $ latest_filename = $ entry; 
} 
  } 
 
 header(“Cache-Control:public”); 
 header(“Content-Description:File Transfer”); 
 header(“Content-Disposition:attachment; filename = $ time.ipa”);  
 header(“Content-Type:application / ipa”); 
 header(“Content-Transfer-Encoding:binary”); 
 //从磁盘读取文件
 readfile(“done / $ time /”  。$ latest_filename); 
 // header('location:dashboard.php'); 
} else {
 // Throwback 
 
die(“失败。联系支持.//&lt; p&gt; $ sign&lt;  / p&gt;“); 
 
} 
   
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题