2

我希望用户能够上传图像或单个图像的 ZIP 文件。目录将存储在一个 zip_upload 文件中,单个图像存储在另一个文件中。我已经掌握了上传过程。但是在服务器上存储文件和目录时会出现问题。

一个有问题的场景:

用户上传了一个名为 A 的 .zip 文件,其中包含 2 个目录,一个名为 B,另一个名为 C。我的问题是如何检查是否有其他目录与 B 或 C 同名。请注意我没有将 A 存储为目录,而是将内部目录 B 和 C 存储。

我一直在使用PHP Zip Extensions

我当前的代码:

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.";
}

谁能给我指出一个解决方案或替代方案来做我想做的事?

4

0 回答 0