问题
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