如何rar一个带有php的文件夹?

发布于 2024-08-28 18:18:27 字数 368 浏览 7 评论 0原文

我只是想在 PHP 的帮助下“rar”一个文件夹。有两种方法可以做到这一点。一种是通过 shell_execexec,这对我不起作用,尽管 shell_execexec 已启用服务器并处理其他命令。

另一种方法是通过 .sh 文件,但我不知道如何正确使用它:(

我需要一些可以正常工作的代码。

我正在尝试使用这个命令:

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

这是 Ubuntu 9.10

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 .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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

白色秋天 2024-09-04 18:18:27

如果其他 shell 命令可以工作,那么 rar 应该可以。

rar.exe 是否在机器上的路径上?或者您是否在命令中指定了 rar.exe 的完整路径?

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?

木緿 2024-09-04 18:18:27

检查工作目录,并尝试使用 passthru 显示输出中的任何错误

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

傲鸠 2024-09-04 18:18:27

使用 php,您可以使用反引号 (``) 来执行来自 php.ini 的命令()。 net

我不确定 rar 会是什么,但 zip 会是:

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

假设您的命令正确并且可以从 cli 访问 rar ,反引号应该起作用。

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.

尛丟丟 2024-09-04 18:18:27

您可能遇到权限问题。检查以确保运行 PHP 的任何用户都有权执行 RAR。

另外,请遵循 Sam 使用完整路径的建议。您的标准路径可能特定于您的用户帐户,这可能与 PHP 使用的用户不同。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文