2012/08/10

PHP force download and rename

$originFile = urlencode($row['origin']); // 原始檔名,加上 urlencode 即便是中文檔名 IE 也可以辨識
$realFile = 'path/'.$row['file']; // 檔案的絕對路徑

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=".$originFile);
header("Content-Description: File Transfer");
@readfile($realFile);

沒有留言: