Created
January 17, 2015 13:20
-
-
Save thagxt/f84643a99003b4db18d8 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 | |
/* | |
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/downunzip.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 | |
$delete = "no"; // if you DO NOT want the .zip file to be deleted after it was extracted set "yes" to "no". | |
/* don't touch nothing after this line */ | |
$file = "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(); | |
echo "<strong>$file</strong> extracted to <strong>$path</strong><br>"; | |
if ($delete == "yes") { unlink($file); } else { echo "remember to delete <strong>$file</strong> & <strong>$script</strong>!"; } | |
} else { | |
echo "Couldn't open $file"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment