The example in this article describes the way PHP downloads files securely. Share to everyone for your reference, specific as follows:
<?php header (' content-type:text/html;
Charset=utf-8 ');
Define (' Root_path ', DirName (__file__)); /** * Download File * @param string $file _path absolute path/function Downfile ($file _path) {//To determine whether a file exists $file _path = iconv (' Utf-8 ' , ' gb2312 ', $file _path); transcoding if (!file_exists ($file _path) for a possible Chinese name) {exit (' file does not exist!
'); } $file _name = basename ($file _path); Gets the file name $file _size = filesize ($file _path); Gets the file size $fp = fopen ($file _path, ' R ');
Open the file header ("Content-type:application/octet-stream") in read-only mode;
Header ("Accept-ranges:bytes");
Header ("Accept-length: {$file _size}");
Header ("content-disposition:attachment;filename={$file _name}");
$buffer = 1024;
$file _count = 0;
To determine whether the file is closed while (!feof ($fp) && ($file _size-$file _count>0)) {$file _data = fread ($fp, $buffer);
$file _count + + $buffer;
echo $file _data; } fclose ($FP); Closes the file} downfile (Root_path. '/down/sunset.jpg ');?>
Description: The name of the file can be accepted in Chinese. The file format is utf-8.
More interested in PHP related content readers can view the site topics: "Php Curl Usage Summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", "PHP Basic Grammar Introductory Tutorial", "PHP operation Office Document skills Summary (including Word, Excel,access,ppt), "The PHP date and time usage summary", "PHP object-oriented Programming Introduction Tutorial", "PHP string (String) Usage Summary", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation skill Summary"
I hope this article will help you with the PHP program design.