Why is the downloaded file damaged ?? What's the problem ??????? Please kindly advise & nbsp; function & nbsp; f ($ file_name, $ file_path) {$ file_name $ _ SERVER [DOCUMENT_ROOT]. $ file_path. $ file_name; & nbsp; $ file_pathiconv (UTF-8, why is the downloaded file damaged ?? What's the problem ??????? Please, what?
Function f ($ file_name, $ file_path ){
$ File_name = $ _ SERVER ['document _ root']. $ file_path. $ file_name;
$ File_path = iconv ("UTF-8", "gb2312", $ file_name );
If (! File_exists ($ file_path ))
// If (! File_exists ($ file_name ))
{
Echo "does not exist ";
Return;
}
$ Fp = fopen ($ file_path, "r ");
$ File_size = filesize ($ file_path );
Header ("Content-type: application/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 );
}
F ("qq.jpg ","/");
Why is the downloaded file damaged ??
Why is the downloaded file damaged ??
Why is the downloaded file damaged ??
Why is the downloaded file damaged ??
Why is the downloaded file damaged ??
------ Solution ----------------------
Tested, no problem.
------ Solution ----------------------
Thunder or something? The downloaded files may be incomplete.
------ Solution ----------------------
Take a look at the screenshot.
In addition, what do you use to open it. What is the code runtime environment?
------ Solution ----------------------
Tested, everything works.
------ Solution ----------------------
Are there any qq.jpg files in the E/Apache/htdocs directory?
------ Solution ----------------------
Open the image file in notepad to see what is there.
------ Solution ----------------------
Your code includes $ file_path = iconv ("UTF-8", "gb2312", $ file_name );
Indicates that your php works in the window system.
The window system strictly distinguishes between text files and binary files.
However, you can use $ fp = fopen ($ file_path, "r") to open binary files in text mode.
So, because you violate the rules, you cannot get the correct result.
You need to open the binary file $ fp = fopen ($ file_path, "rb") in binary mode ");
In addition, your UTF-8 encoded program files must be saved in a format without a BOM header.