[[最後の更新と結論を参照してください、それでも理由を説明できないことで私を悩ませています]]
だから、私はここで奇妙なケースがあります:
zip/rarアーカイブのアップロードに使用するファイルアップロードフォームがあります。ただし、アーカイブ内のファイルに特殊文字が含まれている場合、正しく表示されるものと表示されないものがあります。アップロードおよび移動されたzipファイルにÈ
プラス記号に変換される文字を含むファイルがありますが、文字を含むファイルは正しく保存されます。+
Ö
アップロード前のzipファイル:
Files.zip
Some_file_with_È.pdf
Some_file_with_Î.pdf
Some_file_with_Ñ.pdf
Some_file_with_Ö.pdf
アップロードおよび移動後のzipファイル:
Files.zip
Some_file_with_+.pdf <-- Altered
Some_file_with_+.pdf <-- Altered
Some_file_with_Ñ.pdf
Some_file_with_Ö.pdf
フォーム、.phpファイル、.jsファイル、およびすべてのヘッダーをUTF-8とISO-8859-1 / ANSIの両方でエンコードしてみAddDefaultCharset utf-8
ましたが、Apache構成で設定しましたが、何も変更されていません。
フォームHTML:
<!-- The form. Also tried accept-charset="UTF-8" -->
<form id="uploadzipform" accept-charset="ISO-8859-1">
<input type="file" name="zipfile" id="zipfile">
</form>
<!-- The target iframe to handle fileupload -->
<iframe class="uploadframe" name="zipuploadframe" id="zipuploadframe"></iframe>
jQuery:
$("#uploadzipform").attr(
{
action: "/script/fileupload.php",
method: "POST",
enctype: "multipart/form-data",
target: "zipuploadframe"
});
$("#uploadzipform").submit();
$("#uploadzipform").removeAttr("action method enctype target");
fileupload.php:
/* Irrelevant parts omitted */
$ext = strtolower(pathinfo($_FILES["zipfile"]["name"], PATHINFO_EXTENSION));
// Remove special chars from projectname to make filename
$project = preg_replace('/[^a-zA-Z0-9_ %\[\]\.\(\)%&-]/s', '', substr(utf8_decode($_POST['p']), 0, 9));
$now = date("d-m-Y H.i.s");
$filename = "{$project}_{$now}.{$ext}";
$old = $_FILES["zipfile"]["tmp_name"];
$new = $_SERVER['DOCUMENT_ROOT'] . "/zipfiles/" . $filename;
move_uploaded_file($old, $new);
zip内に特殊文字を含むファイルが変更される可能性はありますか?
編集1
サーバーがWindowsServer2008を実行していることを忘れました
EDIT2
要求に応じて、アップロードされたzipファイルを解凍するコード(7zipコマンドラインを使用):
$file = str_replace("/", "\\", $_POST['f']); // Path to the zipfile
$path = "C:\\pathtoextract";
mkdir("$path");
$cmd = 'C:\\7-Zip\\7z.exe x "' . $file . '" -aou -o' . $path;
// x = extract
// -aou = append existing files with numbers
// -o = path to extract to
exec($cmd);
アップデート
私はいくつかのことを試しました、そしてこれは起こったことです:
ケース1:ちょうどÑ
そしてÖ
Before upload: After upload:
Files.zip Files.zip
Some_file_with_Ñ.pdf Some_file_with_-.pdf <-- Altered (minus?)
Some_file_with_Ö.pdf Some_file_with_+.pdf <-- Altered
ケース2:通常E
およびI
+Ñ
およびÖ
Before upload: After upload:
Files.zip Files.zip
Some_file_with_E.pdf Some_file_with_E.pdf <-- Not altered
Some_file_with_I.pdf Some_file_with_I.pdf <-- Not altered
Some_file_with_Ñ.pdf Some_file_with_-.pdf <-- Altered (minus?)
Some_file_with_Ö.pdf Some_file_with_+.pdf <-- Altered
ケース3:通常I
+ È
、Ñ
およびÖ
Before upload: After upload:
Files.zip Files.zip
Some_file_with_È.pdf Some_file_with_+.pdf <-- Altered
Some_file_with_I.pdf Some_file_with_I.pdf <-- Not altered
Some_file_with_Ñ.pdf Some_file_with_-.pdf <-- Altered (minus?)
Some_file_with_Ö.pdf Some_file_with_+.pdf <-- Altered
ケース4 :Å
、、È
およびÑ
Ö
Before upload: After upload:
Files.zip Files.zip
Some_file_with_Å.pdf Some_file_with_+.pdf <-- Altered
Some_file_with_È.pdf Some_file_with_+.pdf <-- Altered
Some_file_with_Ñ.pdf Some_file_with_-.pdf <-- Altered (minus?)
Some_file_with_Ö.pdf Some_file_with_+.pdf <-- Altered
ケース5:ここでも、最初のアーカイブÈ
、、、Î
Ñ
Ö
Before upload: After upload:
Files.zip Files.zip
Some_file_with_È.pdf Some_file_with_+.pdf <-- Altered
Some_file_with_Î.pdf Some_file_with_+.pdf <-- Altered
Some_file_with_Ñ.pdf Some_file_with_-.pdf <-- Altered (minus?)
Some_file_with_Ö.pdf Some_file_with_+.pdf <-- Altered
うーん..今、すべてが変更されています。
È
ケース6: 、、およびを使用して新しいアーカイブを作成しましÎ
たÑ
Ö
Before upload: After upload:
Files.zip Files.zip
Some_file_with_È.pdf Some_file_with_È.pdf <-- Not altered
Some_file_with_Î.pdf Some_file_with_Î.pdf <-- Not altered
Some_file_with_Ñ.pdf Some_file_with_Ñ.pdf <-- Not altered
Some_file_with_Ö.pdf Some_file_with_Ö.pdf <-- Not altered
結論:zipファイルを編集せず、毎回新しいものを作成してください...
どうやらphpは変更されたアーカイブが好きではないようですが、それでもそのような結果が得られるのは奇妙です。