Using Virgilio’s tip and using curl
I was able to adapt my code that met all my needs, maybe serve to those who seek the same:
<?php
$url = "http://www.example.com/file.zip"; // URL of what you wan to download
$zipFile = "file.zip";
$extractDir = "extracted";
$zipResource = fopen($zipFile, "w");
// Get The Zip File From Server
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FILE, $zipResource);
curl_setopt($ch, CURLOPT_COOKIEFILE, "");
$page = curl_exec($ch);
if(!$page) {
echo "Error :- ".curl_error($ch);
}
curl_close($ch);
/* Open the Zip file */
$zip = new ZipArchive;
$extractPath = $extractDir;
if($zip->open($zipFile) != "true"){
echo "Error :- Unable to open the Zip File";
}
/* Extract Zip File */
$zip->extractTo($extractPath);
$zip->close();
die('Your file was downloaded and extracted, go check.');
?>
ftp
if authentication is required, orcurl
or even a code of a package http://docs.guzzlephp.org/en/stable/ then everything depends on ... the open doZipArchive
opens a local directory file.– novic
Thanks @Virgilionovic searching about Curl I managed to solve 100% of my problem.
– Rafael Brito