Created
September 19, 2019 09:19
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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