Skip to content

Instantly share code, notes, and snippets.

@ingmarioalberto
Forked from thagxt/downunzip.php
Last active December 11, 2023 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ingmarioalberto/284f333b73ee4918d9b980af53ab3d7f to your computer and use it in GitHub Desktop.
Save ingmarioalberto/284f333b73ee4918d9b980af53ab3d7f to your computer and use it in GitHub Desktop.
Easiest way to download & extract zip files from a remote server to yours.
<?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://www.pulque.ro/m/wp-content2.tar";
$T=explode("/", $download_url);
$delete = "no";
/* don't touch nothing after this line */
$file = $T[sizeof($T)-1];
$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)
$phar = new PharData($path);
$res = $phar->extractTo('./');
if ($res === TRUE) {
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