Sometimes we want pieces, text documents, Web pages, MP3, PDFs, and so on, when clicked on the corresponding link to download directly, rather than on the page display, then you need to force the header header information. The following is a piece of PHP function implementation code that does not produce garbled, other programming languages can also be referenced to write the implementation.
Copy CodeThe code is as follows:
/**
* 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
}
}
http://www.bkjia.com/PHPjc/767085.html www.bkjia.com true http://www.bkjia.com/PHPjc/767085.html techarticle sometimes we want to film, text documents, Web pages, MP3, PDFs and other content, when clicked on the corresponding link to download directly, instead of appearing on the page, then you need to force the header letter ...