-
-
Save skerbis/9f6f2d180913bd031e2279e9bda562c1 to your computer and use it in GitHub Desktop.
Download and unzip file with PHP
This file contains hidden or 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 | |
$ch = curl_init(); | |
$source = "https://yourDomain.tld/file.zip"; | |
curl_setopt($ch, CURLOPT_URL, $source); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
$data = curl_exec ($ch); | |
curl_close ($ch); | |
// Save file | |
$destination = "file.zip"; // NEW FILE LOCATION | |
$file = fopen($destination, "w+"); | |
fputs($file, $data); | |
fclose($file); | |
echo " zip downloaded; "; | |
// unzip | |
$zip = new ZipArchive; | |
$res = $zip->open('file.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; '; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment