-
-
Save leotop/edd1a8937db0bc9a66090419cadcc9b6 to your computer and use it in GitHub Desktop.
Download and unzip file with PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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