PHP force File Download-PHP source code

Source: Internet
Author: User
PHP force File Download PHP force File Download


/** * Downloader * * @param $archivo *  path al archivo * @param $downloadfilename *  (null|string) el nombre que queres usar para el archivo que se va a descargar. *  (si no lo especificas usa el nombre actual del archivo) * * @return file stream */function download_file($archivo, $downloadfilename = null) {    if (file_exists($archivo)) {        $downloadfilename = $downloadfilename !== null ? $downloadfilename : basename($archivo);        header('Content-Description: File Transfer');        header('Content-Type: application/octet-stream');        header('Content-Disposition: attachment; filename=' . $downloadfilename);        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($archivo));        ob_clean();        flush();        readfile($archivo);        exit;    }}

The above is the mandatory PHP file download content. For more information, please follow the PHP Chinese network (www.php1.cn )!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.