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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.