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:
Code:
deploy
|-css
|-deploys
||--deploy_*
|||---project_name.zip
||||----project_name
|||---project_name
||||----(list files)
|-files
|-images
|-includes
|-js
The * above is the current date+a rand() number between 1-1000.
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
:
PHP Code:
$sys_folder = 'deploys'; //What folder all the deploys are in
$deploy_download = 'deploy_'.date('smd').rand(1,999); //What the folders will be named
$deploy_dir = $sys_folder.'/'.$deploy_download; //directory where deploy, deploys
if($session !== '' && $session !== 'hd82Dha1LL' && $session !== '1c3dD8320C'){ //Check for default and blank values.
$project_name = $session; //Project name is what they named it.
$safe_name = str_replace(' ', '_', $project_name); //System safe filename.
}
else {
$project_name = "deploy"; //Default project name
$safe_name = "deploy";
}
exec('cp -r '.$deploy_download.' '.$deploy_dir.''); //Copy the temp directory with contents to the new location
remove_dir($deploy_download); //Remove the temp folder and files
exec('cp -r '.$sys_folder.'/'.$deploy_download.' '.$deploy_dir.'/'.$safe_name.''); //Make a duplicate of the newly copied file, but rename it with their project name.
remove_dir($deploy_dir.'/'.$safe_name.'/'.$safe_name); //Kill the infinite looping of folders
exec("zip -r $deploy_dir/$safe_name $deploy_dir/$safe_name");
That's just some snippets from the code that are relevant for this problem.
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!