Last active
February 23, 2022 18:45
-
-
Save thagxt/d9b4388156aeb7f1d66b108d728470d2 to your computer and use it in GitHub Desktop.
Download & Extract .zip with cURL directly on your server
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 | |
$url = "https://wordpress.org/latest.zip"; // URL of what you wan to download | |
$zipFile = "wordpress.zip"; // Rename .zip file | |
$extractDir = "extracted"; // Name of the directory where files are extracted | |
$zipResource = fopen($zipFile, "w"); | |
// Get The Zip File From Server | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_FAILONERROR, true); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
curl_setopt($ch, CURLOPT_AUTOREFERER, true); | |
curl_setopt($ch, CURLOPT_BINARYTRANSFER,true); | |
curl_setopt($ch, CURLOPT_TIMEOUT, 10); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); | |
curl_setopt($ch, CURLOPT_FILE, $zipResource); | |
$page = curl_exec($ch); | |
if(!$page) { | |
echo "Error :- ".curl_error($ch); | |
} | |
curl_close($ch); | |
/* Open the Zip file */ | |
$zip = new ZipArchive; | |
$extractPath = $extractDir; | |
if($zip->open($zipFile) != "true"){ | |
echo "Error :- Unable to open the Zip File"; | |
} | |
/* Extract Zip File */ | |
$zip->extractTo($extractPath); | |
$zip->close(); | |
die('Your file was downloaded and extracted, go check.'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment