Skip to content

Instantly share code, notes, and snippets.

@Alexander-Pop
Forked from thagxt/dl-ex.php
Last active February 23, 2022 18:45
Show Gist options
  • Save Alexander-Pop/488f1f17c9f22982c976468ab812f398 to your computer and use it in GitHub Desktop.
Save Alexander-Pop/488f1f17c9f22982c976468ab812f398 to your computer and use it in GitHub Desktop.
Download & Extract .zip with cURL #php #curl #file #zip
<?php
$url = "https://wordpress.org/latest.zip";
$zipFile = "wordpress.zip"; // Local Zip File Path
$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 = "path_to_extract";
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 probably extracted, check.');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment