Skip to content

Instantly share code, notes, and snippets.

@sedflix
Forked from philipp-r/download-unzip.php
Last active August 21, 2018 15:59
Show Gist options
  • Save sedflix/7c83958cadc0de7b6356a0174c672dcf to your computer and use it in GitHub Desktop.
Save sedflix/7c83958cadc0de7b6356a0174c672dcf 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://github.com/geekSiddharth/student-senate/archive/master.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 = "master.zip"; // NEW FILE LOCATION
$file = fopen($destination, "w+");
fputs($file, $data);
fclose($file);
echo " zip downloaded; ";
// unzip
$zip = new ZipArchive;
$res = $zip->open('master.zip'); // zip datei
if ($res === TRUE) {
$zip->extractTo('.'); // verz zum entpacken
$zip->close();
echo ' zip extracted; ';
unlink('master.zip');
echo ' zip deleted; ';
} else {
echo ' unzip failed; ';
}
@nicolaschaillan
Copy link

Heard of error management?!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment