Home  >  Article  >  Backend Development  >  Implementation of PHP file download function_PHP tutorial

Implementation of PHP file download function_PHP tutorial

WBOY
WBOYOriginal
2016-07-14 10:06:58740browse

/**
*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...
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