简体   繁体   English

删除上传的zip文件中多余的空目录

[英]Remove excess empty directories in uploaded zip file

I am trying to remove excess directories from an uploaded zip file. 我正在尝试从上传的zip文件中删除多余的目录。

For example I would like to transform : 例如,我想转换:

/folder1/folder2/folder3/ [Files are in this folder] / folder1 / folder2 / folder3 / [文件在此文件夹中]

to

/folder1/[files are in this folder] / folder1 / [文件在此文件夹中]

Any help would be appreciated, Thanks. 任何帮助,将不胜感激,谢谢。

Hello, 你好,

I am trying to remove excess directories from an uploaded zip file. 我正在尝试从上传的zip文件中删除多余的目录。

For example I would like to transform : 例如,我想转换:

/folder1/folder2/folder3/ [Files are in this folder] / folder1 / folder2 / folder3 / [文件在此文件夹中]

to

/folder1/[files are in this folder] / folder1 / [文件在此文件夹中]

Any help would be appreciated, Thanks. 任何帮助,将不胜感激,谢谢。

edit: 编辑:

what I have so far is 我到目前为止所拥有的是

function zip_extract($file, $extractPath)
{
  $zip = new ZipArchive;
  $res = $zip->open($file);
  if ($res === TRUE)
  {
    $zip->extractTo($extractPath); 
    $zip->close();
    return TRUE;
  }
  else
  {
     return FALSE;
  }
} 

I'm not sure how to go about removing the unwanted directories though. 我不确定如何删除不需要的目录。

If you are using a linux you can call from PHP; 如果您使用的是Linux,则可以从PHP调用;

<?php
exec('mv /folder1/folder2/folder3/ /folder1');
?>

Reference for MV command MV命令参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM