Sample code for the phpreadfile function to download files and determine permissions
- /**
- * Example of applying the header and readfile functions
- * Download object judgment permission
- * Edit bbs.it-home.org
- */
- $ File = get_file_address (); // the actual address of the file (url is supported, but url is not recommended)
-
- If (file_exists ($ file ))
- {
- Header ('content-Description: File Transfer ');
- Header ('content-Type: application/octet-stream ');
- Header ('content-Disposition: attachment; filename = '. basename ($ file ));
- Header ('content-Transfer-Encoding: binary ');
- Header ('expires: 0 ');
- Header ('cache-Control: must-revalidate, post-check = 0, pre-check = 0 ');
- Header ('pragma: public ');
- Header ('content-Length: '. filesize ($ file ));
- Ob_clean (); // note the call of this function. clear the function but do not disable the output cache. Otherwise, the first two characters of the downloaded file will be 0a.
- Flush ();
- Readfile ($ file); // output file content
- }
- ?>
|