Skip to content

Instantly share code, notes, and snippets.

@aalfiann
Forked from philipp-r/download-unzip.php
Created May 14, 2018 06:06
Show Gist options
  • Save aalfiann/ba0d0155ed69880b33b9dd9331399634 to your computer and use it in GitHub Desktop.
Save aalfiann/ba0d0155ed69880b33b9dd9331399634 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"; // THE FILE URL
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"; // NEW FILE LOCATION
$file = fopen($destination, "w+");
fputs($file, $data);
fclose($file);
echo " wordpress.zip downloaded; ";
// unzip
$zip = new ZipArchive;
$res = $zip->open('wordpress.zip'); // zip datei
if ($res === TRUE) {
$zip->extractTo('.'); // verz zum entpacken
$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