The example in this article describes the processing method of php file download. Share it with everyone for your reference. The specific analysis is as follows:
php can handle file downloads under various conditions. Let’s take a look at the following example:
<?php header("Content-Type: application/force-download"); header("Content-Disposition: attachment; filename=testname.jpg"); readfile("images/test.jpg"); ?>
Analysis of the above code:
The first line of code is forced download;
The second line of code assigns a name to the downloaded content;
The third line of code reads the downloaded content into the file.
I have always thought that it is impossible to download multiple files at the same time in one page, because PHP cannot send download information after the first header.
Today I finally found out a solution, using iframe.
<iframe src="1.zip" style="border-style:none;width:0;height:0;"> </iframe> <iframe src="2.zip" style="border-style:none;width:0;height:0;"> </iframe>
You can also use js to generate iframe
I hope this article will be helpful to everyone’s PHP programming design.