如何使用 PHP 从网站下载特定类型的所有文件?

发布于 2024-08-31 02:40:42 字数 727 浏览 4 评论 0 原文

我想从目录树结构设置非常简单的站点获取所有 midi (*.mid) 文件。我希望我们在这里安装了 wget,但那是另一方......

该网站是 VGMusic.com 包含所有 MIDI 文件的路径是:

http://www.vgmusic.com/music/console/nintendo/nes/

我尝试将其 glob 出来,但我认为 glob 只能在本地工作?

这是我为了实现这一目标而写的内容(显然行不通……):

<?php 
echo 'not a blizzard<br>';
foreach(glob('http://www.vgmusic.com/music/console/nintendo/nes/*.mid') as $filename)
{
    echo $filename.'<br>';
    //$newfile = 'http://www.mydomain.com/nes/'.$filename;
    //copy($filename, $newfile)
}
?>

我也尝试过在没有 http:// 的情况下进行操作,但没有成功。

I want to get all midi (*.mid) files from a site that's set up pretty simple in terms of directory tree structure. I wish we had wget installed here, but that's another party....

The site is VGMusic.com and the path containing all of the midi files is:

http://www.vgmusic.com/music/console/nintendo/nes/

I tried glob'ing it out, but I suppose that glob only works locally?

Here is what I wrote to try to make it happen (doesn't work.. obviously..):

<?php 
echo 'not a blizzard<br>';
foreach(glob('http://www.vgmusic.com/music/console/nintendo/nes/*.mid') as $filename)
{
    echo $filename.'<br>';
    //$newfile = 'http://www.mydomain.com/nes/'.$filename;
    //copy($filename, $newfile)
}
?>

I tried it also without the http:// in there with no luck.

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

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

发布评论

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

评论(1

满地尘埃落定 2024-09-07 02:40:42

事实上 glob 只适用于本地文件系统。

在您的情况下,您必须解析页面 http://www .vgmusic.com/music/console/nintendo/nes/index-classic.html 并搜索类似于 href="(*.mid)" 的字符串,然后请求这些网址。

这是一个很好的正则表达式示例,应该表现得相当好: http ://www.the-art-of-web.com/php/parse-links/

但是,如果您只想拥有所有这些文件,我建议您最好使用某种“全部下载”浏览器插件。

Indeed glob only works on the local filesystem.

In your case you have to parse the page http://www.vgmusic.com/music/console/nintendo/nes/index-classic.html and search for strings that look like href="(*.mid)" and after that request those urls.

This is a good example of a regexp that should perform reasonably well: http://www.the-art-of-web.com/php/parse-links/

However, if you just want to have all those files I'd say you better use some sort of 'download all' browser plugin.

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