Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save christopher-paul-shaw/da357934fdefc1d70ca284ef7b4b9df2 to your computer and use it in GitHub Desktop.
Save christopher-paul-shaw/da357934fdefc1d70ca284ef7b4b9df2 to your computer and use it in GitHub Desktop.
PHP Script for Downloading Files from Specific URLS and keeping the Directory Structure.
<?php
$host = "https://www.example.com";
$target_dir = './download';
$urls = [
'/img/header.png',
'/js/example.js',
'/styles/global.css',
];
foreach ($urls as $u) {
$target = "{$target_dir}/{$u}";
$directories = explode('/', $target);
$current = false;
array_pop($directories);
foreach ($directories as $d){
$current .= "{$d}/";
if (!is_dir($current)) {
mkdir($current);
}
}
$content = file_get_contents("{$host}{$u}");
file_put_contents($target,$content);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment