Home > Backend Development > PHP Tutorial > php-PHP can only download pictures named in English, but not pictures named in Chinese. What should I do?

php-PHP can only download pictures named in English, but not pictures named in Chinese. What should I do?

PHP中文网
Release: 2023-03-02 22:22:01
Original
1714 people have browsed it

PHP can only download pictures named in English, but not pictures named in Chinese. What should I do?

php

php-PHP can only download pictures named in English, but not pictures named in Chinese. What should I do?

<?php
    function down_file($file_name,$file_sub_dir){
        $file_name=iconv("utf-8","gb2312",$file_name);

        $file_path=$_SERVER[&#39;DOCUMENT_ROOT&#39;].$file_sub_dir.$file_name;
        if(!file_exists($file_path)){
            echo "文件不存在";
            return;
        }
        $fp=fopen($file_path,"r");
        $file_size=filesize($file_path);
        /*if($file_size>30){
            echo "<script language=&#39;javascript&#39;>window.alert(&#39;文件过大&#39;);</script>";
            return;
        }*/

        header("Content-type: application/octet-stream");
        header("Accept-Ranges: bytes");
        header("Accept-Length: $file_size");
        header("Content-Disposition: attachment; filename=".$file_name);

        $buffer=1024;
        $file_count=0;
        while(!feof($fp) && $file_size-$file_count>0){
            $file_data=fread($fp,$buffer);
            $file_count+=$buffer;
            echo $file_data;
        }

        fclose($fp);
    }

    down_file("answer.jpg","/http/");

?>
Copy after login

php-PHP can only download pictures named in English, but not pictures named in Chinese. What should I do?

php-PHP can only download pictures named in English, but not pictures named in Chinese. What should I do?

Successfully downloaded and opened successfully:

php-PHP can only download pictures named in English, but not pictures named in Chinese. What should I do?

Then I changed the last sentence

 down_file("answer.jpg","/http/");
Copy after login

to

down_file("答案.jpg","/http/");
Copy after login
in the fileDown.php file of the first picture

And changed the name of the picture in the site from "answer.jpg" to "answer.jpg", I refreshed the address:

http://localhost/http/fileDown.php

As a result, it popped up this dialogue for me Box:

php-PHP can only download pictures named in English, but not pictures named in Chinese. What should I do?

Why isn’t the file name “Answer.jpg”? What was downloaded in the end was not a picture.
What’s the reason?

Reply content:

http://www.php.cn/php-weizijiaocheng-300416.html


I had an idea and cut the code in the fileDown.php file into the EditPlus editor , and then saved it to the same location in the site, overwriting the fileDown.php file originally edited with the Notepad++ editor. This time not only can it be downloaded successfully, but the image can also be opened successfully. After fussing for a long time, I found out that it was a problem with the Notepad++ editor! As a beginner, I can actually find bugs in Notepad++, a world-famous editor. Everyone should tell others and learn from it! hey-hey.

php-PHP can only download pictures named in English, but not pictures named in Chinese. What should I do?


php-PHP can only download pictures named in English, but not pictures named in Chinese. What should I do?

By the way, the picture above is my answer to the following question. If anyone has an account on the PhD Mathematics Forum, please help this poor brother.
Or if any of you have extra accounts that you don’t use, please give one to me.

http://www.math.org.cn/forum.php?mod=viewthread&tid=37021

The above is php-PHP can only download images named in English, but what should I do if it cannot download images named in Chinese? For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

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 Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template