php實現下載文件(瀏覽器不直接打開)

test.html:
<a href="do.php?ac=dw">下載12.jpg</a>php

do.php:
if($_GET['ac']=='dw') {html

$file = './12.jpg';   //文件路徑

$filename = basename($file); //要下載文件的名字

header("Content-Type: application/force-download");

header("Content-Disposition: attachment; filename=".($filename));

readfile($file);

}app

相關文章
相關標籤/搜索