2010-04-16 108 views
0

我想知道PHP腳本中的命令來獲取輸出並從我的網站保存文件。 謝謝從網站下載文件PHP

+1

你是說,你想知道如何啓動用戶瀏覽你的網站文件下載? – Kazar 2010-04-16 09:05:11

+3

對不起,這不是很清楚你想要什麼。你可以嘗試用不同的文字或例子來解釋它嗎? – deceze 2010-04-16 09:05:34

+0

*(參考)* http://de2.php.net/manual/en/function.header.php(請參閱示例#1下載對話框) – Gordon 2010-04-16 09:08:47

回答

1

請參閱here瞭解如何強制輸出php腳本的下載。

它的基本功能是:

// Set headers 
header("Cache-Control: public"); 
header("Content-Description: File Download"); 
header("Content-Disposition: attachment; filename=" + $filename); 
header("Content-Type: application/zip"); // or whatever the mime-type is 
              // for the file you want to download 
header("Content-Transfer-Encoding: binary"); 

// Read the file from disk 
readfile($full_path_to_file); 

作爲補充(戈登的評論提供),請參見PHP文檔here

0

一號例如在文件的結束或者點擊使用文件,你可以添加此

 $filesh = "check.xls"; 

     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=".basename($filesh)); 
     header("Content-Description: File Transfer"); 
     readfile($filesh); 

,如果你使用的問題意味着,)你可以添加ob_start文件的頂部(有任何頭;功能

0

如果你的意思是獲得輸出,從其他站點或位置的內容,爲此,你需要什麼file_get_contents