Skip to content

Instantly share code, notes, and snippets.

@philipp-r
Last active October 20, 2023 13:32
Show Gist options
  • Save philipp-r/8da66054f1ea3fe7311fa872b422d3b4 to your computer and use it in GitHub Desktop.
Save philipp-r/8da66054f1ea3fe7311fa872b422d3b4 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; ';
}
@camilo0506
Copy link

c

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