Jason Curran Posted June 8, 2009 Share Posted June 8, 2009 I'm trying to zip up the folder "website" as seen in the code below. But when I open the Zip file, the files I am trying to Zip are 5 directories deep in the zip file. Does anyone know a way to have the zip file contain only the actual directory and not all of the directories in the path ? <?php if (system('zip -r /home/path/to/my/website/newzipfile.zip /home/path/to/my/website')) { echo '<p>It worked!</p>'; } else { echo '<p>It did NOT work!</p>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/161408-php-zip-question/ Share on other sites More sharing options...
MadTechie Posted June 8, 2009 Share Posted June 8, 2009 as a guess i would say remove the -r but it depends on the command, check the docs or use ZipArchive (see PHP manual) Quote Link to comment https://forums.phpfreaks.com/topic/161408-php-zip-question/#findComment-851785 Share on other sites More sharing options...
ldougherty Posted June 8, 2009 Share Posted June 8, 2009 Exactly, -r means "operate recursively on directories" therefore you are including all sub directories If you remove the -r you should be fine. Quote Link to comment https://forums.phpfreaks.com/topic/161408-php-zip-question/#findComment-851816 Share on other sites More sharing options...
Jason Curran Posted June 8, 2009 Author Share Posted June 8, 2009 Removing the -r still Zips all directories above "website" .. but it does not zip the directories below "website" .. not a good thing Quote Link to comment https://forums.phpfreaks.com/topic/161408-php-zip-question/#findComment-851819 Share on other sites More sharing options...
MadTechie Posted June 8, 2009 Share Posted June 8, 2009 but it does not zip the directories below "website" .. not a good thing Erm.. and -r DID ?! Quote Link to comment https://forums.phpfreaks.com/topic/161408-php-zip-question/#findComment-851823 Share on other sites More sharing options...
ldougherty Posted June 8, 2009 Share Posted June 8, 2009 I don't use zip but im pretty sure your syntax is off zip [-aABcdDeEfFghjklLmoqrRSTuvVwXyz!@$] [-b path] [-n suffixes] [-t mmddyyyy] [-tt mmddyyyy] [ zipfile [ file1 file2 ...]] [-xi list] for your case shouldn't it be zip -r /home/path/to/my/website/* /home/path/to/my/website/newzipfile.zip that should include /website and everything under it, or remove the -r for just the content of /website Quote Link to comment https://forums.phpfreaks.com/topic/161408-php-zip-question/#findComment-851826 Share on other sites More sharing options...
MadTechie Posted June 8, 2009 Share Posted June 8, 2009 Ahhh under that directory makes sense, when he said below that directory that's confused the nuts off me! Quote Link to comment https://forums.phpfreaks.com/topic/161408-php-zip-question/#findComment-851834 Share on other sites More sharing options...
Jason Curran Posted June 8, 2009 Author Share Posted June 8, 2009 Thanks for the help so far .. the solutions have NOT worked .. and have actually led to some unexpected results .. instead of using example code, I will post the actual code that I am using .. I have two scripts. Script #1 works. Script #2 does NOT work. I am trying to zip all folders inside the "makefolders" directory. Inside of the "makefolders" directory, I have 2 directories, "test1" and "test2". In Script #1, I am getting the results I am expecting. All of the directories inside of the "makefolders" directory are indluded in the Zip file, but I am also getting all of the directories in the path: "/home/folders/public_html/makefolders" Here is a link to Script #1 live on server where you can download the Zip file that is created: http://www.foldersfromlist.com/working.php Here is the code for Script#1 <?php $dl_url = 'http://www.foldersfromlist.com/testme.zip'; if (system('zip -r /home/folders/public_html/testme.zip /home/folders/public_html/makefolders/')) { echo '<p>It worked!</p>'; echo '<a href="' . $dl_url . '">Download</a>'; } else { echo '<p>It did NOT work!</p>'; } ?> If I remove the "-r" from Script #1, the directories under "makefolders" are not included in the Zip file, and the directories in the path are still included in the Zip file. Script #2 does not work, with or without the "-r" For Script #2, I tried the code syntax posted by ldoughtery zip -r /home/path/to/my/website/* /home/path/to/my/website/newzipfile.zip Script #2 actually creates a zip file called "test1.zip" inside of the "makefolders" directory and inside "test1.zip" is the directory "test2" Here is a link to Script #2 live on server where you can download the Zip file that is created: http://www.foldersfromlist.com/notworking.php <?php $dl_url = 'http://www.foldersfromlist.com/testme.zip'; if (system('zip -r /home/folders/public_html/makefolders/* /home/folders/public_html/testme.zip')) { echo '<p>It worked!</p>'; echo '<a href="' . $dl_url . '">Download</a>'; } else { echo '<p>It did NOT work!</p>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/161408-php-zip-question/#findComment-851904 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.