【备注】1,采用流的方式获取 2,采用while 循环形式取, 每次取的时候 清空缓存, 否则图片就不完整 。 红色标记部分重要。
$file_path='/data/www/1.jpg';
$file_size = filesize($file_path);$fp = fopen($file_path, "r");
// 返回的文件
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="图片.jpg"');
header( 'Content-Length: ' . filesize ( $file_path) );
header( 'Cache-Control: max-age=0' );
header("Accept-Ranges: bytes");
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
$fp = fopen ( $file_path, 'r' );
while ( ! feof ( $fp ) ) {
$buffer = fread ( $fp, 10 );
ob_flush ();
flush ();
echo $buffer;
}
ob_flush ();
flush ();
ob_clean ();
fclose ( $fp );
exit();

&spm=1001.2101.3001.5002&articleId=78443620&d=1&t=3&u=fc1c2567ca9f4d6395a9c7cac7e8e0a8)
2923

被折叠的 条评论
为什么被折叠?



