How does PHP download images instead of opening them! Example: PHP & nbsp; how can I download a specified image? Instead of opening it in a browser? PHP Image Download PHP how to download images instead of opening them!
Example:
How does PHP download specified images? Instead of opening it in a browser?
PHP image download
Share:
------ Solution --------------------
$file = "/tmp/dummy.tar.gz";
header("Content-type: application/octet-stream");
header('Content-Disposition: attachment; filename="' . basename($file) . '"');
header("Content-Length: ". filesize($file));
readfile($file);
------ Solution --------------------
I will post you a story about how Han Shunping talked about php download, hoping to help you. If you need to watch the video, you can watch Han Shunping's php video tutorial 87th:
The code is as follows:
// Description of the function
// Parameter description $ file_name file name
// $ File_sub_dir: the sub-path of the downloaded file '"/xxx /"
Function down_file ($ file_name, $ file_sub_dir ){
// Click it to download an image.
// If the file is in Chinese.
// The cause is the php file function, which is relatively old and needs to be transcoded for Chinese gb2312.
$ File_name = iconv ("UTF-8", "gb2312", $ file_name );
// Absolute path
$ File_path = $ _ SERVER ['document _ root'] [
]. $ File_sub_dir. $ file_name;
// 1. open the file
If (! File_exists ($ file_path )){
Echo "the file does not exist! ";
Return;
}
$ Fp = fopen ($ file_path, "r ");
// 2. process files
// Obtain the size of the downloaded object
$ File_size = filesize ($ file_path );
If ($ file_size> 30 ){
Echo"