Get the App
SLTechnology News&Howtos  ›  Development  › 

How to force php to download files

Shulou Source: shulou.com Published: 2022-06-01 03:24:44 11月27日 Update

This article will explain in detail how to force php to download files. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Forced download of files

$filename = $_ GET ['file']; / / Get the fileid from the URL / / Query the file ID $query = sprintf ("SELECT * FROM tableName WHERE id ='% s'", mysql_real_escape_string ($filename)); $sql = mysql_query ($query); if (mysql_num_rows ($sql) > 0) {$row = mysql_fetch_array ($sql); / / Set some headers 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-Type: application/octet-stream"); header ("Content-Type: application/download"); header ("Content-Disposition: attachment; filename=" .basename ($row ['FileName']); "; header (" Content-Transfer-Encoding: binary "); header (" Content-Length: ".filesize ($row [' FileName'])) @ readfile ($row ['FileName']); exit (0);} else {header ("Location: /"); exit;} this is the end of the article on "how to force php to download files". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: File mandatory article more good practical content article knowledge reference help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Information Huawei Docker MySQL