Skip to content


wget in php

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

Posted in Development, PHP, System Administration.

Tagged with , .


One Response

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

Continuing the Discussion

  1. wget - StartTags.com linked to this post on 26.01.2010

    [...] target so I cna wget the file straight to the machine. I cannot seem to do that from my cusotmr …wget in php | Christian RiesenOk, this is far from what wget is capable of, but most people do only need one function for wget. [...]

You must be logged in to post a comment.