-
-
Save ppprakhar/bd2ed055991c6618172d2cf9f5cbbbe7 to your computer and use it in GitHub Desktop.
Easiest way to download & extract zip files from a remote server to yours.
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 | |
// Identify directories | |
$source = __DIR__ . "/wordpress"; | |
$destination = __DIR__; | |
// Cycle through all source files | |
function move_all($source, $destination) { | |
if (is_dir($source)) { | |
// Make the destination directory if not exist | |
@mkdir($destination); | |
// Get array of all source files | |
foreach (scandir($source) as $i => $file) { | |
if (in_array($file, array(".", ".."))) continue; | |
move_all($source . '/' . $file, $destination . '/' . $file); | |
} | |
rmdir($source); | |
} else { | |
rename($source, $destination); | |
} | |
} | |
/* | |
1) upload this file into the folder you'd like to extract the content of the downloaded .zip file. | |
2) run the script in you browser. i.e. http://localhost/install-wp.php | |
3) after the script was executed sucesfully, login thru ftp and remove this script | |
*/ | |
/* you can change this */ | |
$download_url = "https://wordpress.org/latest.zip"; // url to zip file you want to download | |
/* don't touch nothing after this line */ | |
$file = __DIR__ . "/file.zip"; | |
$script = basename($_SERVER['PHP_SELF']); | |
// download the file | |
file_put_contents($file, fopen($download_url, 'r')); | |
// extract file content | |
$path = pathinfo(realpath($file), PATHINFO_DIRNAME); // get the absolute path to $file (leave it as it is) | |
$zip = new ZipArchive; | |
$res = $zip->open($file); | |
if ($res === TRUE) { | |
$zip->extractTo($path); | |
$zip->close(); | |
move_all($source, $destination); | |
echo "<strong>$file</strong> extracted to <strong>$path</strong><br>"; | |
unlink($file); | |
unlink(__FILE__); | |
?> | |
<script> | |
window.location.href = window.location.href.replace('install-wp.php', ''); | |
</script> | |
<?php | |
} else { | |
echo "Couldn't open $file"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment