PHP can only download pictures named in English, but not pictures named in Chinese. What should I do?
php
<?php function down_file($file_name,$file_sub_dir){ $file_name=iconv("utf-8","gb2312",$file_name); $file_path=$_SERVER['DOCUMENT_ROOT'].$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='javascript'>window.alert('文件过大');</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/"); ?>
Successfully downloaded and opened successfully:
Then I changed the last sentence
down_file("answer.jpg","/http/");
to
down_file("答案.jpg","/http/");
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:
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.
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)!