在php中从wget获取文件名

发布于 2024-10-05 22:54:40 字数 283 浏览 0 评论 0原文

我正在设置一个脚本,以便我可以输入网页的 URL,该脚本将 wget 文件。然而,大多数文件都是 *.rar 格式。我是否可以将文件名传递给 unrar 命令来解压通过 wget 下载的文件?

非常非常感谢!

编辑 我考虑过使用 PHP 的 explode() 函数通过斜杠 (/) 分解 URL,但这似乎有点 hack-y 。

I'm setting up a script so that I can input a URL to a web page and the script will wget the file. Most of the files, however, will be in the *.rar format. Is there anyway I can pass the filename to the unrar command to unarchive the files downloaded via wget?

Many, many thanks in advance!

EDIT I thought about using PHP's explode() function to break up the URL by the slashes (/) but that seems a bit hack-y.

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

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

发布评论

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

评论(4

捎一片雪花 2024-10-12 22:54:40

您应该考虑使用 PHP 自己的 cURLRAR 扩展。您可以使用 tmpfile() 函数创建临时文件,使用它作为 CURLOPT_FILE 选项的值,使 cURL 将下载的文件保存在那里,然后使用 RAR 函数打开该文件以提取内容。

Rather than forking out to external programs to download and extract the file, you should consider using PHP's own cURL and RAR extensions. You can use the tmpfile() function to create a temporary file, use it as the value of the CURLOPT_FILE option to make cURL save the downloaded file there, and then open that file with the RAR functions to extract the contents.

甜味拾荒者 2024-10-12 22:54:40

使用 basename() 获取文件名。

Use basename()to get the filename.

Spring初心 2024-10-12 22:54:40

@Wyzard 给出了最佳答案。如果有一个库可以解决您的问题,请使用它而不是分叉外部进程。它更安全,而且是干净的解决方案。 PHP 的 cURLRAR 很好,使用它们。

但是,如果您必须使用 wgetunrar,那么@rik 给出了一个很好的答案。 wget-O filename 选项将文件保存为 filename,因此您不必计算它。不过,我宁愿使用 wget -q -O - http://www.example.com |解压

@Byron 的答案很有帮助,但你真的不需要在这里使用它。然而,它比您编辑提到的使用 explode() 更好。

@Wyzard gives the best answer. If there's a library that solves your problem, use it instead of forking an external process. It's safer and it's the clean solution. PHP's cURL and RAR are good, use them.

However, if you must use wget and unrar, then @rik gives a good answer. wget's -O filename option saves the file as filename, so you don't have to work it out. I would rather pipe wget's output directly to unrar though, using wget -q -O - http://www.example.com | unrar.

@Byron's answer is helpful, but you really should not need to use it here. It is, however, better than using explode() as your edit mentions.

不离久伴 2024-10-12 22:54:40

wget -O 文件名 URL &&解压文件名

wget -O filename URL && unrar filename

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