Note that there are some explanatory texts on larger screens.

plurals
  1. POZipping files in a folder without a parent folder in the zipped file
    text
    copied!<p>This maybe a silly question to most, but I have the following folder, which I want to zip.</p> <pre><code>FolderI Folder1 Folder2 Folder3 .. .. FolderN </code></pre> <p>Now, zipping up <code>FolderI</code> into a <code>zipFile.zip</code> is pretty easy because of so many resources online, specially here! But, I want to create <code>zipFile.zip</code>, containing <code>Folder1...FolderN</code>, such that when the file is unzipped, it would directly populate the current directory with <code>Folder1...FolderN</code>,instead of creating <code>FolderI</code>, which has <code>Folder1...FolderN</code> in it.</p> <p>Some of the things I've been trying are:</p> <pre><code>$zip = new ZipArchive(); // open archive if ($zip-&gt;open('my-archive.zip', ZIPARCHIVE::CREATE) !== TRUE) { die ("Could not open archive"); } // initialize an iterator // pass it the directory to be processed $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("FolderI/")); // iterate over the directory // add each file found to the archive foreach ($iterator as $key=&gt;$value) { $zip-&gt;addFile(realpath($key), $key) or die ("ERROR: Could not add file: $key"); } // close and save archive $zip-&gt;close(); </code></pre> <p>This was picked up from <a href="https://stackoverflow.com/questions/3828385/compress-archive-folder-using-php-script">compress/archive folder using php script</a> and I tried to change it around. Didn't work though - <em>The FolderI is still zipped. But, when I unzip the <code>my-archive.zip</code>, I get a <code>FolderI</code> and then <code>Folder1..FolderN</code> inside it</em>. I also saw code from @Alix somewhere here, which did the same thing. But, didn't really follow much.</p> <p>Any kind of help would be great. If not the code, at least point me to the right direction. </p> <p>Thanks</p> <p>****Anyone here knows how to do this? ****</p> <p>@Mods and Admins: Is the solution too simple or PHP can't do this at all?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload