Link to home
Start Free TrialLog in
Avatar of terencepires
terencepires

asked on

Create zip file using php and exec()

hi there,

i'm trying to create a zip file on my server using php and the exec() command and here is the output i get :

Warning: ftp_get(test100401120201.zip) [function.ftp-get]: failed to open stream: Permission denied

my code is attached below, i'm on an ubuntu system

any ideas ?

Cheers

Terence
$zipRemoteFileName = "/var/www/teleskiDev/tmp/teleski" . $date . ".zip";
$zipLocalFileName = "teleski" . $date . ".zip";			  
$zipCommand = "sudo -u root zip $zipRemoteFileName ";
foreach($files as $file) {
	$zipCommand .= $this->pwd . "/" . escapeshellcmd($file) . " ";
}
echo $zipCommand;
system($zipCommand);

Open in new window

Avatar of Kruger_monkey
Kruger_monkey
Flag of United Kingdom of Great Britain and Northern Ireland image

Permission denied.  Looks like the script is trying to work, but doesn't have the necessary permission.

Does apache have access to the folder in question?  Check the access permissions on the folder, assuming your page is running under apache the user that apache runs under needs to have write permissions to the folder in question.
Avatar of terencepires
terencepires

ASKER

ok, how can i do that ?
On the server where the php script is you need to make sure the access to this folder is high enough fro apache to write to.

/var/www/teleskiDev/tmp/

Check the ownership and current permissions.

This article shows you how to set the permissions via your script.  Not sure about the 777 being necessary, but it may be.  If this is a public facing server, you may want to reset that

http://forums.digitalpoint.com/showthread.php?t=382036
ok i tried that but it still doesn't work

maybe i have to put apache in the sudoers group ? that too i don't know how to do
ok, i tried to add the apache user to the sudoers group using visudo, like below

stopped / restarted server without effect...

# User alias specification
User_Alias      APACHE = www-data

# Cmnd alias specification
Cmnd_Alias      ZIP = /usr/bin/zip

# User privilege specification
root    ALL=(ALL) ALL

# Uncomment to allow members of group sudo to not need a password
# (Note that later entries override this, so you might need to move
# it further down)
%sudo ALL=NOPASSWD: ALL
APACHE  ALL = (ALL) NOPASSWD: ZIP

Open in new window

The sudoer files isn't really necessary as far as I know as they aren't going to be using sudo.

As a test, can you chmod 777  /var/www/teleskiDev/tmp/

This will set your tmp folder for world writeable access.  It will also be worth if you can do the following on the server that hosts the page.

tail -f /var/log/httpd/error.log

Watch that log file while you try the file and post whatever pops up if anything.
ok, here's what i get :

[Thu Apr 01 13:09:23 2010] [error] [client 89.156.181.70] File does not exist: /var/www/favicon.ico
      zip warning: name not matched: /home/terence/Rakefile
      zip warning: name not matched: /home/terence/backup.sql
      zip warning: name not matched: /home/terence/configuration.php
      zip warning: name not matched: /home/terence/photos.php
      zip warning: name not matched: /home/terence/teleski.zip
      zip warning: name not matched: /home/terence/test
      zip warning: name not matched: /home/terence/test.tite
      zip warning: name not matched: /home/terence/test.titi
      zip warning: name not matched: /home/terence/test.titz
      zip warning: name not matched: /home/terence/toto.zip

zip error: Nothing to do! (/var/www/teleskiDev/tmp/teleski100401130925.zip)

i then tried to do :
   cat /home/terence/test.titi

and it worked...
Can you check what the file sizes are on those files listed above.  

See the name not match highlight here.

http://wiki.linuxquestions.org/wiki/Zip
Check the following as well to see if that applies to you if the file sizes are small.

http://www.kplaylist.net/forum/viewtopic.php?f=4&t=2384
- well the sizes are really small (a few kb's) and the command works when typing it from ssh

- i was using PHP's escapeshellcmd() so i tried without it, to get the same result...
ASKER CERTIFIED SOLUTION
Avatar of Kruger_monkey
Kruger_monkey
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
solved !
thanks !