All posts
Engineering 1 min read

Simple wget written in PHP

First off, this does not do what wget can do, but only exists to make getting a file easier. I needed something that did just that, getting a file from a URL to complete some installations on multiple machines. They had a working PHP environment but no wget and I was not allowed to install it.

So if you just need the basic operation, grab a file, then this is for you.

<?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