Php implements simple file download methods ,. Php implements simple file download. this example describes how php implements simple file download. Share it with you for your reference. The following describes how to download simple php files on behalf of php,
This example describes how to download simple files in php. Share it with you for your reference. The details are as follows:
The PHP file download code introduced here is a simple implementation of the download function of an image, which is not complete yet. it is best to encapsulate it into a class or use function calls. Interested friends can be improved on this basis!
The PHP file download code is as follows:
<? Php $ file_name = "2.jpg"; // define (" SPATH ","/php/image/") of the image to be downloaded /"); // The relative path for storing images $ file_sub_path = $ _ SERVER ['document _ root']; // The absolute address of the website ROOT directory $ file_path = $ file_sub_path.SPATH. $ file_name; // absolute image address, that is, the first three connections // Determine whether the object exists if (! File_exists ($ file_path) {echo "this file does not exist"; return ;}$ fp = fopen ($ file_path, "r "); // open the file $ file_size = filesize ($ file_path); // get the file size/** header used to download the file */header ("Content-type: application/octet-stream "); header (" Accept-Ranges: bytes "); header (" Accept-Length :". $ file_size); header ("Content-Disposition: attachment; filename = ". $ file_name); $ buffer = 1024; $ file_count = 0; // return data to the browser while (! Feof ($ fp) & $ file_count <$ file_size) {$ file_con = fread ($ fp, $ buffer); $ file_count + = $ buffer; echo $ file_con; // if no echo exists, only files of 0 bytes will be downloaded.} fclose ($ fp);?>
I hope this article will help you with php programming.
Example: This article describes how to download a simple php file. Share it with you for your reference. The details are as follows: PHP file download generation described here...