Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP zip archive adds extra folder
    primarykey
    data
    text
    <p>I have a piece of code which generates a .zip archive containing all files and folders from a given folder. It looks like this:</p> <pre><code>function zipDirectory($source, $destination, $flag = '') { if (!extension_loaded('zip') || !file_exists($source)) { return false; } $zip = new ZipArchive(); if (!$zip-&gt;open($destination, ZIPARCHIVE::CREATE)) { return false; } $source = str_replace('\\', '/', realpath($source)); if($flag) { $flag = basename($source) . '/'; //$zip-&gt;addEmptyDir(basename($source) . '/'); } if (is_dir($source) === true) { $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST); foreach ($files as $file) { $file = str_replace('\\', '/', realpath($file)); if (is_dir($file) === true) { $zip-&gt;addEmptyDir(str_replace($source . '/', '', $flag.$file . '/')); } else if (is_file($file) === true) { $zip-&gt;addFromString(str_replace($source . '/', '', $flag.$file), file_get_contents($file)); } } } else if (is_file($source) === true) { $zip-&gt;addFromString($flag.basename($source), file_get_contents($source)); } return $zip-&gt;close(); } zipDirectory($downloadID.'/','temp_'.$downloadID.'.zip', false); $zip_file = 'temp_'.$downloadID.'.zip'; $file_name = basename($zip_file); header("Content-Type: application/zip"); header("Content-Disposition: attachment; filename=" . $file_name); header("Content-Length: " . filesize($zip_file)+15); </code></pre> <p>However, the resulting .zip archive ends up containing the specified folder, as well as an extra folder called "C:" with folders inside it, making up the absolute path to the root of my site. There are no files in this chain of folders.</p> <p>I don't really know what could be causing this... Any ideas? Would be much appreciated.</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.
    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