The question of writing and downloading images. This post was last edited by bianyu1983 in 2013-02-0922: 17: 02?file_name4=jpg; if (! File_exists ($ file_name) {echo & nbsp; the file does not exist;} $ fpfopen ($ file_name, r); $ file_sizefilesize: the problem of downloading images.
This post was last edited by bianyu1983 at 22:17:02 on
$ File_name = "420.jpg ";
If (! File_exists ($ file_name )){
Echo 'file does not exist ';
}
$ Fp = fopen ($ file_name, "r ");
$ File_size = filesize ($ file_name );
Header ("content-type: appliation/octet-stream ");
Header ("accept-ranges: bytes ");
Header ("accept-length:". $ file_size );
Header ("content-disposition: attachment; filename =". $ file_name );
$ Buffer = 1024;
While (! Feof ($ fp )){
$ File_data = fread ($ fp, $ buffer );
Echo $ file_data;
}
Fclose ($ fp );
The above code downloads the image. the downloaded image is 20 bytes larger than the original image. The downloaded image is blank.
------ Solution --------------------
$ Fp = fopen ($ file_name, "rb ");
------ Solution --------------------
$ File_name = "420.jpg ";
If (! File_exists ($ file_name )){
Echo 'file does not exist ';
}
An exit should be added after echo;
Or:
Exit ("The file does not exist. ");