TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 09-26-2008, 08:20 AM   #1 (permalink)
The Wanderer
 
Join Date: Jun 2008
Posts: 19
Thanks: 0
oscargodson is on a distinguished road
Default 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:

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!
oscargodson is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 01:02 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design