Get the App
SLTechnology News&Howtos  ›  Development  › 

How php forces picture downloads by modifying header

Shulou Source: shulou.com Published: 2022-06-03 19:45:53 10月01日 Update

This article mainly introduces how php through the modification of header forced picture download, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

The specific implementation methods are as follows:

Function downloadFile ($file) {$file_name = $file; $mime = 'application/force-download'; header (' Pragma: public'); / / required header ('Expires: 0'); / / no cache header (' Cache-Control: must-revalidate, post-check=0, pre-check=0'); header ('Cache-Control: private',false); header (' Content-Type:'. $mime); header ('Content-Disposition: attachment; filename= "' .basename ($file_name).'') Header ('Content-Transfer-Encoding: binary'); header (' Connection: close'); readfile ($file_name); / / push it out exit ();} Thank you for reading this article carefully. I hope the article "how php forces picture downloads by modifying header" shared by the editor will be helpful to you. At the same time, I hope you will support us, pay attention to the industry information channel, and more related knowledge is waiting for you to learn!

Tags: Articles pictures picture downloads compulsion value interest at the same time methods more friends knowledge editing industry information information channels channels references learning help support Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology MariaDB Shulou Tech Info NVidia Docker