What should I do if the php file download shows that the file cannot be found?

藏色散人
Release: 2023-03-05 10:02:01
Original
2257 people have browsed it

The solution to the problem that the php file download shows that the file cannot be found: first open the corresponding download code file; then obtain the character encoding from the browser; then use the "mb_convert_encoding" function to convert the encoding; finally use "file_exists" Just download the function implementation file.

What should I do if the php file download shows that the file cannot be found?

Recommendation: "PHP Video Tutorial"

Solution for php file download and file_exists cannot find the file

Link:Click to download

Among them, php:

"; if( empty($filename)){ echo''; exit(); } if (!file_exists($filename)) { //检查文件是否存在 echo "文件找不到"; exit; } else { $file = fopen($filename,"r"); // 打开文件 // 输入文件标签 Header("Content-type: application/octet-stream"); Header("Accept-Ranges: bytes"); Header("Accept-Length: ".filesize($filename)); Header("Content-Disposition: attachment; filename=" . $filename); // 输出文件内容 echo fread($file,filesize($filename)); fclose($file); exit(); } ?>
Copy after login

Summary: If the file address passed in by the browser is not transcoded (from UTF-8 to GBK), then the file_exists function will not be able to find the file with a Chinese name.

The above is the detailed content of What should I do if the php file download shows that the file cannot be found?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!