讓下載的URL連結不會被直接開啟而是顯示儲存對話框

“怕失憶筆記”看到的,怕有一天會用到,先記下來~~

方法一:
$downloadfile=”somefile.txt”;
header(”Content-disposition: attachment; filename=$downloadfile”);
header(”Content-Type: application/force-download”);

方法二:

$file_name = “file.name”;
$file_path = “/path/to/realfile”;
$file_size = filesize($file_path);
header(‘Pragma: public’);
header(‘Expires: 0’);
header(‘Last-Modified: ‘ . gmdate(‘D, d M Y H:i ‘) . ‘ GMT’);
header(‘Cache-Control: must-revalidate, post-check=0, pre-check=0’);
header(‘Cache-Control: private’, false);
header(‘Content-Type: application/octet-stream’);
header(‘Content-Length: ‘ . $file_size);
header(‘Content-Disposition: attachment; filename=”‘ . $file_name . ‘”;’);
header(‘Content-Transfer-Encoding: binary’);
readfile($file_path);
?>

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *