php - Create Zip from array of files in directory -
i'm trying create zip file files contained in folder on server.
here's code:
$zip = new ziparchive(); $dirarray = array(); $new_zip_file = $temp_unzip_path.'test_new_zip.zip'; $new = $zip->open($new_zip_file, ziparchive::create); if ($new === true) { $handle = opendir($temp_unzip_path); while (false !== ($entry = readdir($handle))) { $dirarray[] = $entry; } print_r ($dirarray); closedir($handle); } else { echo 'failed create zip'; } $zip->close();
i'm new php trying piece php manual along examples i've found on net.
i have set print_r
in there temporarily create sure entries beingness added array - planning set rest of zip functions in future.
my problem it's not printing anything, don't know if files getting added zip or not.
my code wrong (i hope not) if can point me in right direction i'd grateful.
thanks.
i've modified code , creates zip file without problems. if isn't working check permissions in directory mydirectory
<pre><? $temp_unzip_path = './mydirectory/'; $zip = new ziparchive(); $dirarray = array(); $new_zip_file = $temp_unzip_path.'test_new_zip.zip'; $new = $zip->open($new_zip_file, ziparchive::create); if ($new === true) { $handle = opendir($temp_unzip_path); while (false !== ($entry = readdir($handle))) { if(!in_array($entry,array('.','..'))) { $dirarray[] = $entry; $zip->addfile($temp_unzip_path.$entry,$entry); } } print_r ($dirarray); closedir($handle); } else { echo 'failed create zip'; } $zip->close(); ?>
php arrays zip
No comments:
Post a Comment