Exec(zip) in PHP not working as expected
I have used this function before and I use the exec function quite frequently, but for some reason I can't get this to work right. No matter what the path is (as long as the path returns true) it always zips the "deploys" directory. Here is my directory structure real quick:
Here is how it works so you get the idea:
- Person clicks deploy
- the files are generated in a temp location in the root (deploy) directory
- the folder is copied via exec(cp)
- folder is removed from the temp location
- The folder then makes a copy of its self inside its self with the user's project name.
- Now it should zip THIS, the project_name directory.
However, it zips the deploys directory everytime no matter what the path is. Here is a snippet of the processing code I'm talking about:
You might seem some code that is repeating a variable like $sys_folder.'/'.$deploy_download and it's only there because I have been messing with it a lot.
Any ideas at all why it would be doing this on a Mac OS X (UNIX) system? It will be uploaded to a Linux box when it's finished, so I'm hoping I can get it working cross platform.
Thanks in advance!
hmm, I dunno tbh I'll have to do some further research.
try this to see what its actually doing:
Also (off topic slightly) would using 'mv' instead of copying and deleting dirs help?
Here is my log (different files each time, but same basic thing.)
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:
|All times are GMT. The time now is 02:41 PM.|
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0