Php function zip folder no works -
Php function zip folder no works -
i utilize 1 function see here zip folders , , works nice see great problem when utilize kind of slash ../
the function :
<?php function zip($source, $destination) { if (!extension_loaded('zip') || !file_exists($source)) { homecoming false; } $zip = new ziparchive(); if (!$zip->open($destination, ziparchive::create)) { homecoming false; } $source = str_replace('\\', '/', realpath($source)); if (is_dir($source) === true) { $files = new recursiveiteratoriterator(new recursivedirectoryiterator($source), recursiveiteratoriterator::self_first); foreach ($files $file) { $file = str_replace('\\', '/', $file); // ignore "." , ".." folders if (in_array(substr($file, strrpos($file, '/') + 1), array('.', '..'))) continue; $file = realpath($file); if (is_dir($file) === true) { $zip->addemptydir(str_replace($source . '/', '', $file . '/')); } else if (is_file($file) === true) { $zip->addfromstring(str_replace($source . '/', '', $file), file_get_contents($file)); } } } else if (is_file($source) === true) { $zip->addfromstring(basename($source), file_get_contents($source)); } homecoming $zip->close(); } ?>
in case need zip folders out of file function zipping works
when utilize function slash , result it´s within zip there nil , it´s empty
if seek utilize code folders in same level , , no need utilize "../" works fine
actually problem it´s when utilize function in way :
<?php zip("../images","backup_images.zip") ?>
but if utilize here , works right
<?php zip("images","backup_images.zip") ?>
can substitute absolute path instead?
zip("../images","backup_images.zip")
becomes:
zip("/var/www/vhosts/domain.com/httpdocs/full/path/to/images","backup_images.zip")
you can utilize phpinfo();
within php file in same place backup_images.zip find right directory.
php zip
Comments
Post a Comment