Note that there are some explanatory texts on larger screens.

plurals
  1. POzip main folder with sub folder inside
    primarykey
    data
    text
    <p>I have a folder with some files and sub folder inside. How im going to read the directory and zip the main folder? </p> <p>Ex:</p> <pre><code>maindirectory --- file 1 --- file 2 --- subdirectory 1 ------ file 3 ------ file 4 --- subdirectory 2 ------ file 5 ------ file 6 </code></pre> <p>I'm using this script:</p> <pre><code>function Zip($source, $destination, $include_dir = false) { if (!extension_loaded('zip') || !file_exists($source)) { return false; } if (file_exists($destination)) { unlink ($destination); } $zip = new ZipArchive(); if (!$zip-&gt;open($destination, ZIPARCHIVE::CREATE)) { return false; } $source = str_replace('\\', '/', realpath($source)); if (is_dir($source) === true) { $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_CHILD); if ($include_dir) { $arr = explode("/",$source); $maindir = $arr[count($arr)- 1]; $source = ""; for ($i=0; $i &lt; count($arr) - 1; $i++) { $source .= '/' . $arr[$i]; } $source = substr($source, 1); $zip-&gt;addEmptyDir($maindir); } foreach ($files as $file) { $file = str_replace('\\', '/', $file); // Ignore "." and ".." folders if( in_array(substr($file, strrpos($file, '/')+1), array('.', '..')) ) continue; $file = realpath($file); if (is_dir($file) === true) { $zip-&gt;addEmptyDir(str_replace($source . '/', '', $file . '/')); } else if (is_file($file) === true) { $zip-&gt;addFromString(str_replace($source . '/', '', $file), file_get_contents($file)); } } } else if (is_file($source) === true) { $zip-&gt;addFromString(basename($source), file_get_contents($source)); } return $zip-&gt;close(); } </code></pre> <p>and I call the function like this: </p> <pre><code>Zip('image/data/','aaa.zip',false); </code></pre> <p>But what I get is it zip the whole <code>C:</code> folder. What I want is to only zip document inside the <code>image/data/</code> folder.</p> <p>How can I format the correct directory and it's subdirectories?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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