相关疑难解决方法(0)

PHP Force下载导致0字节文件

我正在尝试使用PHP从我的Web服务器强制下载文件.我不是PHP的专家,但我似乎无法解决大小为0字节的文件下载问题.

码:

$filename = "FILENAME...";

header("Content-type: $type");
header("Content-Disposition: attachment;filename=$filename");
header("Content-Transfer-Encoding: binary");
header('Pragma: no-cache');
header('Expires: 0');
set_time_limit(0);
readfile($file);
Run Code Online (Sandbox Code Playgroud)

有人可以帮忙吗?谢谢.

php download

7
推荐指数
2
解决办法
2万
查看次数

PHP readfile()和大量下载

在设置在线文件管理系统的同时,现在我已经遇到了障碍.

我正在尝试使用此修改版本的readfile将文件推送到客户端:

function readfile_chunked($filename,$retbytes=true) { 
   $chunksize = 1*(1024*1024); // how many bytes per chunk 
   $buffer = ''; 
   $cnt =0; 
   // $handle = fopen($filename, 'rb'); 
   $handle = fopen($filename, 'rb'); 
   if ($handle === false) { 
       return false; 
   } 
   while (!feof($handle)) { 
       $buffer = fread($handle, $chunksize); 
       echo $buffer; 
       ob_flush(); 
       flush(); 
       if ($retbytes) { 
           $cnt += strlen($buffer); 
       } 
   } 
       $status = fclose($handle); 
   if ($retbytes && $status) { 
       return $cnt; // return num. bytes delivered like readfile() does. 
   } 
   return $status; 
}
Run Code Online (Sandbox Code Playgroud)

但是当我尝试下载一个13 …

php download

5
推荐指数
1
解决办法
5368
查看次数

标签 统计

download ×2

php ×2