没什么好解释的,反正就是弹出个下载框提示下载
不这么写直接转到.rar之类的文件一般的浏览器也会弹出下载,但jpg这种类型的文件就会直接显示出来,而不是下载了
$path = "images/test.jpg";
try {
if (is_file ( $path )) {
if ($file = fopen ( $path, 'rb' )) {
/**
* connection_status() 函数返回当前的连接状态。
*
* 可返回的可能值:
*
* •0 - CONNECTION_NORMAL - 连接运行正常
* •1 - CONNECTION_ABORTED - 连接由用户或网络错误终止
* •2 - CONNECTION_TIMEOUT - 连接超时
* •3 - CONNECTION_ABORTED & CONNECTION_TIMEOUT
*/
while ( ! feof ( $file ) and (connection_status () == 0) ) {
$f .= fread ( $file, 1024 * 8 );
}
fclose ( $file );
}
$outputname = "myimage";
header ( "Content-type: image/jpeg" );
header ( "Content-disposition: attachment; filename=" . $outputname . ".jpg" );
print $f;
} else {
throw new exception ( "文件路径错误。" );
}
} catch ( exception $e ) {
echo $e->getmessage ();
}