View Single Post
Old 09-28-2008, 12:00 PM   #4 (permalink)
oscargodson
The Wanderer
 
Join Date: Jun 2008
Posts: 19
Thanks: 0
oscargodson is on a distinguished road
Default

FINALLY! So many hours and I finally figured it out.

Alright here is the explanation in case anyone ever needs to zip a file with the exec() function.

Since zip -r recursively zips files (zips all files and directories inside the CURRENT directory) you need to find out how you are trying to zip the files.

a. Zipping the files with your script in the SAME directory as the file/directory you are trying to zip. E.g. Zipping gallery with a script inside of gallery would zip gallery + all the files and directories inside of gallery.
This would be no problem.

b. (this is what I was trying to do.) Zip your files from another location like a parent directory. E.g. Try to zip gallery from /home/tmp/gallery would zip home, tmp, gallery and all of their subdirectories. Not what you wanted probably.

So, how do you do these both?

a. exec("zip -r myzip mydirectory")
b. exec("cd home/tmp; zip -r myzip mydirectory")

In b, we had to change the directory to be a sibling of the directory we wanted to zip, THEN zip directory. Technically, without doing that it's zipping the "./" and "../" thats why you get all the files above it as well.

Hope this helps someone in the future :)

Oh by the way, my fix was to make the:
PHP Code:
exec("zip -r $deploy_dir/$safe_name $deploy_dir/$safe_name"); 
to:

PHP Code:
exec("cd $deploy_dir; zip -r $safe_name $safe_name"); 
oscargodson is offline  
Reply With Quote