Skip to content

Instantly share code, notes, and snippets.

@gjreasoner
Last active May 20, 2019 20:27
Show Gist options
  • Save gjreasoner/59cdc51b74fa96685b713ed23f4ef6d0 to your computer and use it in GitHub Desktop.
Save gjreasoner/59cdc51b74fa96685b713ed23f4ef6d0 to your computer and use it in GitHub Desktop.
Download images in place
#!/usr/bin/php
<?php
# Install:
# wget https://gist.githubusercontent.com/gjrdiesel/59cdc51b74fa96685b713ed23f4ef6d0/raw/Downloader.php -O /usr/local/bin/dl
# chmod +x /usr/local/bin/dl
if(!isset($argv[1])){
echo "Downloader: This downloads the full URL and makes a matching file structure\n";
die("Usage: dl [url]");
}
$url = $argv[1];
$path = ltrim(parse_url($url)['path'],'/');
$file = basename($path);
$directory = str_replace($file,'',$path);
@mkdir($directory);
file_put_contents($path,file_get_contents($url));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment