提取ZIP文件目录 - PHP

时间:2012-11-23 14:43:33

标签: php file-upload zip directory

我希望用户能够上传图像的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.";
}

有人能指出我做我想要的解决方案或替代方案吗?

0 个答案:

没有答案