简体   繁体   中英

Remove excess empty directories in uploaded zip file

I am trying to remove excess directories from an uploaded zip file.

For example I would like to transform :

/folder1/folder2/folder3/ [Files are in this folder]

to

/folder1/[files are in this folder]

Any help would be appreciated, Thanks.

Hello,

I am trying to remove excess directories from an uploaded zip file.

For example I would like to transform :

/folder1/folder2/folder3/ [Files are in this folder]

to

/folder1/[files are in this folder]

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;

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

Reference for MV command

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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