Skip to content

Instantly share code, notes, and snippets.

@leotop
Forked from philipp-r/download-unzip.php
Created April 4, 2021 15:57
Show Gist options
  • Save leotop/edd1a8937db0bc9a66090419cadcc9b6 to your computer and use it in GitHub Desktop.
Save leotop/edd1a8937db0bc9a66090419cadcc9b6 to your computer and use it in GitHub Desktop.
Download and unzip file with PHP
<?php
// get latest german WordPress file
$ch = curl_init();
$source = "https://de.wordpress.org/latest-de_DE.zip";
curl_setopt($ch, CURLOPT_URL, $source);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec ($ch);
curl_close ($ch);
// save as wordpress.zip
$destination = "wordpress.zip";
$file = fopen($destination, "w+");
fputs($file, $data);
fclose($file);
echo " wordpress.zip downloaded; ";
// unzip
$zip = new ZipArchive;
$res = $zip->open('wordpress.zip');
if ($res === TRUE) {
$zip->extractTo('.'); // directory to extract contents to
$zip->close();
echo ' wordpress.zip extracted; ';
unlink('wordpress.zip');
echo ' wordpress.zip deleted; ';
} else {
echo ' unzip failed; ';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment