How to download all files of a specific type from a website using PHP?
I want to get all midi files (* .mid) from a site that is pretty simplistic in terms of directory tree structure. We wish we could install wget here, but that's the other side ....
The VGMusic.com website , and the path containing all MIDI files is:
http://www.vgmusic.com/music/console/nintendo/nes/
I tried glob but I suppose glob only works locally?
Here's what I wrote to try and do it (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 also tried this without http://
where no luck.
a source to share
Indeed glob only works on the local filesystem.
In your case, you need to parse the page http://www.vgmusic.com/music/console/nintendo/nes/index-classic.html and look for lines that look like href = "(*. Mid)" and after that ask these urls.
This is a good example of a regular expression that should perform well enough: http://www.the-art-of-web.com/php/parse-links/
However, if you just want to have all of these files, I would say that you are better off using a "paid" browser plugin.
a source to share