开发者

How rar a folder with php?

I simply want to 'rar' a folder with the help of PHP. There are 2 ways to do this. One is via shell_exec or exec, which isn't working for me, although shell_exec and exec are enabled on the server and working for other commands.

The other method is via 开发者_JAVA百科.sh file, but I don't know how to use it properly :(

I need some code which works properly for this.

I'm trying to use this command:

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

It's Ubuntu 9.10


if other shell commands work then rar should.

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


Check the working directory, and try using passthru to display any error from the output


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

I'm not sure what it would be to rar, but zip would be:

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

Assuming your command is correct and rar is accessible from cli the backticks should work.


You likely have a permissions problem. Check to make sure that whatever user PHP is running as has access to execute RAR.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜