Jump to content

Write And Zip


manalnor

Recommended Posts

Hello dear friends,

 

let say we have text file (file.txt)

 

i wanna php code that makes me able to write some text to this text file (file.txt) then save it as zipped file to be (zipped.zip)

 

1) I know how to write , will use this

 

<?php 
$File = "file.txt"; 
$Handle = fopen($File, 'w');
$Data = "Hello phpfreaks\n"; 
fwrite($Handle, $Data); 
$Data = "Hello World\n"; 
fwrite($Handle, $Data); 
print "Data Written"; 
fclose($Handle); 
?>

 

now the (file.text) will be saved with the following text

 

Hello phpfreaks
Hello World

 

Now the question which i do not know  :shrug: how to save it as zipped file not text file ? OR save it normally as text file (file.txt) then create zipped file of it (zipped.zip)

 

thank you so much for help  :)

Link to comment
https://forums.phpfreaks.com/topic/231645-write-and-zip/
Share on other sites

Look into the ZipArchive class.  I believe this extension is preloaded on most hosts, but if it's not on yours, you should contact your webhost to have it added.  A quick phpinfo() will show you if it's there.

 

And of course, if you manage your own server, compile PHP using --enable-zip (on Linux) or enable php_zip.dll in your php.ini (on Windows).

Link to comment
https://forums.phpfreaks.com/topic/231645-write-and-zip/#findComment-1191969
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.