但若要人下載,怎麼辦
因為工作上需要做到這個功能
上網survey了一下
原來是利用header的設定
設定-Content-disposition: attachment
即可
這樣程式看起來會像
<?php
header('Content-disposition: attachment; filename=名稱'); //存檔會出現的名稱
header('Content-type: MIME型態); //可參照前一篇的速查表
readfile(檔案位址); //
?>
像我是要讓他下載html,所以mime就設text/html
實際寫出來就像
.....
header('Content-disposition: attachment; filename=$title.html');
header('Content-type: text/html');
readfile('$url');
.....
沒有留言:
張貼留言