Implementation of PHP file download function_PHP tutorial

WBOY
Release: 2016-07-14 10:06:58
Original
771 people have browsed it

/**
*File download function
* @param string $fileName file name
* @param string $fileExt file suffix name
​*/
function downloadFile($fileName, $fileExt = '.txt' )
{
    if( empty($fileName)) return FALSE;
    $fileName .= $fileExt;
    $filePath = TEMI_UPLOAD_PATH . $fileName;
    $file = fopen($filePath, "r");
    Header("Content-type: application/octet-stream");
    Header("Accept-Ranges: bytes");
    Header("Accept-Length: " . filesize($filePath));
    Header("Content-Disposition: attachment; filename=" . $fileName);
    echo fread($file, filesize($filePath));
    fclose($file);
}
?>
 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/477902.htmlTechArticle?php /*** File download function * @param string $fileName file name * @param string $fileExt file suffix name*/ function downloadFile($fileName, $fileExt = .txt ) { if( empty($f...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template