Home >Backend Development >PHP Problem >What to do if the php file download path is incorrect

What to do if the php file download path is incorrect

藏色散人
藏色散人Original
2022-01-21 09:32:082319browse

Solution to the incorrect php file download path: 1. Use a relative path when judging the file path; 2. Execute "iconv('UTF-8','GB2312',$file_path)"; 3. Just set "$file_size" greater than 0.

What to do if the php file download path is incorrect

The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer

What should I do if the php file download path is incorrect?

The php file download path does not exist or the download content is empty

I am working on a project these days and need to upload and download files. After working for a long time, either the file path is wrong, or there is no content in the downloaded php file. The download path does not exist or the download content is empty. Finally, I found that it is all a trap... Let’s sort out the points that need attention:

1. When judging the file path, use a relative path. It must be a relative path;

2. The path is correct, but when using the file_exists() function, it still prompts that the path does not exist, then you need to check Does the file name contain Chinese? If so, please transcode it:

$file_path = iconv('UTF-8','GB2312',$file_path);

3. After all the above is correct, you find that the downloaded file is empty, so you need to pay attention to Header("Accept-Length:".$ file_size) inside $file_size must be greater than 0;

The above are the pitfalls I encountered when downloading files, maybe I am trapping myself! The php file download path does not exist or the download content is empty

Recommended study: "PHP Video Tutorial"

The above is the detailed content of What to do if the php file download path is incorrect. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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