【备注】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();