I want to create a zip file, the content of the file was retrieved from another website. For example I have file:
http://examples.com/path/file.txt
and I want to download file.txt
as a zip file. I tried with file_get_contents();
but it's not working.
$content = file_get_contents(http://examples.com/path/file.txt);
$zip = new ZipArchive;
$res = $zip->open('config.zip', ZipArchive::CREATE);
if ($res === TRUE) {
$zip->addFromString(file.txt, $content);
$zip->close();
echo 'OK';
} else {
echo 'Failed';
}
I think it will get the content of file.txt
, and create a compressed zip file, but when i open the output file it is not (incomplete sentence).