How to rar a folder with php?

I just want a "rar" folder using PHP. There are two ways to do this. One is via shell_exec

or exec

, which doesn't work for me, although shell_exec

it is exec

enabled on the server and works for other commands.

Another method is via file .sh

, but I don't know how to use it correctly :(

I need some code that works correctly for this.

I am trying to use this command:

rar a -v100m -m0 /home/admin/somefolder.rar somefolder-to-rar

This is Ubuntu 9.10

+2


source to share


4 answers


if other shell commands work, then rar.



is rar.exe on the way to the machine? or are you giving the full path to rar.exe in your command?

+1


source


Check your working directory and try using passthru

to display any error from the exit



+1


source


With php you can use backticks ('') to execute command ( from php.net )

I'm not sure if this will be with rar, but the zip will be:

<?php
  `cd $dirToZip; zip -pr $nameOfZipFile *`
?>

      

Assuming your command is correct and the rar is available from the cli, the reverse steps should work.

0


source


You probably have a permissions issue. Make sure any custom PHP is running as it has access to execute RAR.

Also, follow Sam's suggestion to use the full path. Your default path may be specific to your user account, which may be different for the user using PHP.

0


source







All Articles