Ich habe beim Herunterladen von Dateien in IE 11 verstümmelte Zeichen gefunden.
Ich habe die Informationen online überprüft und herausgefunden, dass der Hauptgrund darin liegt, dass sich der Benutzeragent geändert hat. Es ist nicht mehr MSIE, sondern rv: 11.0, solange der Server feststellt, dass es sich um IE 11 handelt, und es genauso behandelt wie MSIE.
GO:
<span>func</span><span></span><span>setDownloadFileName</span><span>(</span>w<span></span>http<span>.</span>ResponseWriter<span>,</span><span></span>fileName<span>,</span><span></span>agent<span></span><span>string</span><span>)</span><span></span><span>{</span>
<span> </span><span>if</span><span></span>strings<span>.</span>Contains<span>(</span>agent<span>,</span><span></span><span>"MSIE"</span><span>)</span><span></span><span>{</span>
<span> </span>fileName<span></span><span>=</span><span></span>url<span>.</span>QueryEscape<span>(</span>fileName<span>)</span>
<span> </span>fileName<span></span><span>=</span><span></span>strings<span>.</span>Replace<span>(</span>fileName<span>,</span><span></span><span>"+"</span><span>,</span><span></span><span>"%20"</span><span>,</span><span></span><span>-</span><span>1</span><span>)</span>
<span> </span><span>}</span>
<span> </span><span>if</span><span></span>strings<span>.</span>Contains<span>(</span>agent<span>,</span><span></span><span>"rv:"</span><span>)</span><span></span><span>&&</span><span></span>strings<span>.</span>Contains<span>(</span>agent<span>,</span><span></span><span>"Gecko"</span><span>)</span><span></span><span>{</span>
<span> </span>fileName<span></span><span>=</span><span></span>url<span>.</span>QueryEscape<span>(</span>fileName<span>)</span>
<span> </span>fileName<span></span><span>=</span><span></span>strings<span>.</span>Replace<span>(</span>fileName<span>,</span><span></span><span>"+"</span><span>,</span><span></span><span>"%20"</span><span>,</span><span></span><span>-</span><span>1</span><span>)</span>
<span> </span><span>}</span>
<span> </span>w<span>.</span>Header<span>().</span>Set<span>(</span><span>"Content-Disposition"</span><span>,</span><span></span><span>"attachment;filename=\""</span><span>+</span>fileName<span>+</span><span>"\""</span><span>)</span>
<span>}</span>
PHP:
$ua = isset ( $_SERVER ["HTTP_USER_AGENT"] ) ? $_SERVER ["HTTP_USER_AGENT"] : ''; <span style="white-space:pre"> </span> if (preg_match ( "/MSIE/", $ua )) { <span style="white-space:pre"> </span>$file_name = rawurlencode ( $file_name ); <span style="white-space:pre"> </span>header ( 'Content-Disposition: attachment; filename="' . $file_name . '"' ); } else if (preg_match ( "/Firefox/", $ua )) { <span style="white-space:pre"> </span>header ( 'Content-Disposition: attachment; filename*="utf8\'\'' . $file_name . '"' ); } elseif (stripos ( $ua, 'rv:' ) > 0 && stripos ( $ua, 'Gecko' ) > 0) { <span style="white-space:pre"> </span>$file_name = rawurlencode ( $file_name ); <span style="white-space:pre"> </span>header ( 'Content-Disposition: attachment; filename="' . $file_name . '"' ); } else { <span style="white-space:pre"> </span>header ( 'Content-Disposition: attachment; filename="' . $file_name . '"' ); }
Das Obige stellt vor, wie man von IE 11 heruntergeladene chinesische verstümmelte Dateien löst, einschließlich der relevanten Inhalte. Ich hoffe, dass es für Freunde hilfreich ist, die sich für PHP-Tutorials interessieren.