Ok, this is far from what wget is capable of, but most people do only need one function for wget. Enter url, get content. Especially during the setup phase this is often needed and sometimes wget is not available or libraries are missing. For those that have a working php installation but no working wget, this little script does exactly that, download a file and save it locally. This little helper has done valuable services for me now a few times, so here it is for anyone to use.
<?php
// wget substitute
if ($argc != 2) {
?>
This works a bit like wget. Just run it with the url as argumnet
<?php
exit;
}
$url = $argv[1];
$filename = basename($url);
file_put_contents($filename,file_get_contents($url));
echo PHP_EOL. 'Written file ' . $filename . PHP_EOL;
Usage is rather simple now:
php wget.php URL
One Response
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.
Continuing the Discussion
You must be logged in to post a comment.