cakephp download png file

我们两清 提交于 2019-12-25 02:22:06

问题


I dynamically generate png files which after clicking "generate" button appears "under" link.

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

After clicking link DOWNLOAD I wish content of link(in my case png) start download - no open in another window but download! I am using cakePHP. Can I please for help?


回答1:


Alternatively if you are using Apache web server and have mod_headers enabled you can use an .htaccess file to force download of the png files.

Create a .htacess file and place it in the directory where your png files are being generated/downloaded from. In that file put this:

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



回答2:


you can use the MediaView to pass it through and force downloading: http://book.cakephp.org/2.0/en/views/media-view.html?highlight=media#MediaView



来源:https://stackoverflow.com/questions/8888129/cakephp-download-png-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!