2012-01-17 73 views
0

我動態生成png文件,點擊「生成」按鈕後出現「下」鏈接。cakephp下載png文件

"generate button : click" ---> <a href="new_generated.png">DOWNLOAD</a> 

鏈接點擊下載後我想鏈接的內容(在我的情況PNG)開始下載 - 在另一個窗口沒有打開,但下載! 我正在使用cakePHP。我可以請求幫忙嗎?

回答

0

或者和mod_headers中有啓用,您可以使用.htaccess文件,迫使PNG文件的下載。

創建一個.htacess文件,並將其放在您的png文件正在生成/下載的目錄中。在該文件中把這個:

<FilesMatch "\.(?i:png)$"> 
    ForceType application/octet-stream 
    Header set Content-Disposition attachment 
</FilesMatch> 
+0

image = image.replace(「image/png」,「application/octet-stream」); – santBart 2012-01-17 01:27:31

0

可以使用MediaView通過它傳遞和力量下載:如果您正在使用Apache Web服務器 http://book.cakephp.org/2.0/en/views/media-view.html?highlight=media#MediaView

+0

但據瞭解,我必須把它放在「應用程序/ outside_webroot_dir/..」,但生成的文件是「canvas.toDataURL(」圖像/ PNG」,真)的結果; 「我不知道如何將它放在這個目錄中.... – santBart 2012-01-17 00:31:25

+0

好吧,如果是這樣一個tmp生成的文件,你可以使用$ response對象的新的2.0特性:http://book.cakephp.org/2.0 /en/controllers/request-response.html#sending- attachtaments – mark 2012-01-17 00:32:56