ユーザーが画像の ZIP ファイルまたは単一の画像をアップロードできるようにしたい。ディレクトリは zip_upload ファイルに保存され、単一の画像は別のファイルに保存されます。アップロードプロセスをマスターしました。しかし、ファイルとディレクトリをサーバーに保存するときに問題が発生します。
問題のあるシナリオ:
ユーザーが A という名前の .zip ファイルをアップロードします。このファイルには、B と呼ばれるディレクトリと C という名前の 2 つのディレクトリが含まれています。私の質問は、B または C と同じ名前のディレクトリが他にあるかどうかを確認する方法です。 A をディレクトリとして保存するのではなく、内部ディレクトリの B と C を保存します。
PHP Zip拡張機能を使用しています
私の現在のコード:
if($continue == "zip"){
$target_path = "/var/www/....".$filename;
// change this to the correct site path
echo "target: ".$target_path."<br/>";
//if directory already exists
//say that it already exists, please try again
$flag = 1;
//else
//upload the file
//$flag = 0;
if($flag == 1){
if(move_uploaded_file($source, $target_path)) {
$zip = new ZipArchive();
$x = $zip->open($target_path);
if ($x === true) {
$zip->extractTo("/var/www/...");
// change this to the correct site path
$zip->close();
unlink($target_path);
}
$message = "Your .zip file was uploaded and unpacked.";
} else {
$message = "There was a problem with the upload. Please try again.";
}
} else {
$message = "Already a directory called ".$filename. ". Please rename and retry. Note: Please rename the folder within the zip file.";
}
誰かが私がやりたいことをするための解決策または代替案を教えてもらえますか?