Home > Article > Backend Development > PHP Header function implements download short-click resume program_PHP tutorial
This article will summarize several program functions for implementing download short-point resuming. These functions mainly use the header function of PHP. Friends who need to know more can refer to it.
For example: when downloading, output the download file size, file name, etc.
The premise is that the configuration of the .htaccess file needs to add a sentence
SetEnv no-gzip dont-vary
That is, the file will not be compressed
Example 1
Copy code | ||||||||||||||||||||
This function reads the given file pointer from the current position to EOF, and writes the result to the output buffer The above two examples do not support Chinese well, the following function This problem is solved very well
Copy code |
| return false; } $size = filesize($real); $size2 = $size-1; $range = 0; if(isset($ _SERVER['HTTP_RANGE'])) { header('HTTP /1.1 206 Partial Content'); $range = str_replace('=','-',$_SERVER[' HTTP_RANGE']); $range = explode('-',$range); $range = trim($range[1]); header( 'Content-Length:'.$size); header('Content-Range: bytes '.$range.'-'.$size2.'/'.$size); } else { header('Content-Length:'.$size); header('Content-Range: bytes 0-'.$size2.'/'.$size ); } header('Accenpt-Ranges: bytes'); header('application/octet-stream'); header ("Cache-control: public");header("Pragma: public"); //Solve the problem of Chinese garbled characters when downloading in IE $ua = $_SERVER['HTTP_USER_AGENT'];if(preg_match('/MSIE/',$ua)) {$ie_filename = str_replace('+','%20', urlencode($file)); header('Content-Dispositon:attachment; filename='.$ie_filename); } else { header('Content- Dispositon:attachment; filename='.$file); } $fp = fopen($real,'rb+'); fseek($fp,$ range);while(!feof($fp)) {set_time_limit(0);print(fread($fp,1024)); Flush(); ob_flush(); } fclose($fp); *End of PHP*/
http://www.bkjia.com/PHPjc/444606.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444606.htmlTechArticleThis article summarizes several functions for downloading short-point resuming programs. These functions are mainly used Friends who need to know more about the header function of php can refer to it. For example: Download...
Statement: The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn Previous article:PHP uses the PHPExcel class to export and import Excel usage_PHP tutorialNext article:PHP uses the PHPExcel class to export and import Excel usage_PHP tutorial Related articlesSee more |