php - Archive a .wdgt folder in ZipArchive() -
i'm creating online widget creation tool in php, , able export need via .zip , problem users have extract zip , add .wdgt extension on folder work in ibooks. there way make part of process easier, e.g - unzip , .wdgt folder there, or better, download .wdgt.
here code have create zip file:
//zip name $archivename = 'widget.zip'; $filenames = array(); //scan through directories, , add array foreach(scandir($workingdir) $content){ $filenames[] = $workingdir.$content; } foreach(scandir($resources) $content){ $filenames[] = $resources.$content; } archivefiles($filenames, $archivename); function archivefiles($filenames, $archivename){ //init new ziparchive() $zip = new ziparchive(); //open archive $zip->open($archivename); if($zip->open($archivename, ziparchive::overwrite ) !==true){ exit("cannot open <$archivename>\n"); } else{ //archive create, add files foreach($filenames $files){ if('.' === $files || '..' === $files) continue; //get filename , extension $filename = explode("/", $files); $num = (count($filename) - 1); $thefilename = $filename[$num]; //add file archive - full path of file, new filename $zip->addfile($files,$thefilename); } $zip->close(); header( 'location: http://myurl/'.$archivename ) ; //redirects zip archive exit; } }
this works fine. need able either download .wdgt folder content need in it, or able zip .wdgt folder has content need.
i have tried changing $archivename
$archivename = "widget.wdgt.zip";
, $archivename = "widget.wdgt";
the $archivename = "widget.wdgt.zip";
able unzip fine on windows. although on mac gave error. , has work on mac in ibook's author these widgets work on
managed .wdgt folder downloaded within zip file, needed when adding file in loop this:
$zip->addfile($files, 'mywidget.wdgt/'.$thefilename);
by adding 'mywidget.wdgt/'.$thefilename
path addfile() forced ziparchive create mywidget.wdgt folder , adding files it.
Comments
Post a Comment