CodeIgniter Forums
file_write() - file helper - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: file_write() - file helper (/showthread.php?tid=21610)



file_write() - file helper - El Forum - 08-15-2009

[eluser]Bondie[/eluser]
Is there anyway of "backing up" a directory to a .gz using the file write, i tried the following....

I want to backup all of the folders/files in
Quote:./
aka the directories above index.php front controller thingy bob Wink

Code:
$filename = './../backups/backup';

write_file($filename.'.gz', './');



file_write() - file helper - El Forum - 08-15-2009

[eluser]Bondie[/eluser]
any other suggestions of doing it would be lovely, please!!!! Smile


file_write() - file helper - El Forum - 08-15-2009

[eluser]tomcode[/eluser]
You can do it using the directory helper and the zip encoding class.

1. Fetch the directory You want backup with the directory helper.
2. Traverse the array and add the files to a zip using the zip encoding class.


file_write() - file helper - El Forum - 08-15-2009

[eluser]Bondie[/eluser]
Thanks, Didn't realise there was a directory helper, we learn something new everyday! Smile thanks for your help.


file_write() - file helper - El Forum - 08-15-2009

[eluser]Bondie[/eluser]
After TomCodes help, I'm now using this code:
Code:
$this->zip->read_dir('./');
$this->zip->archive($filename);

although the zip is reporting as invalid?






- EDIT FIXED.


file_write() - file helper - El Forum - 08-15-2009

[eluser]tomcode[/eluser]
Try
Code:
$this->zip->read_dir(realpath('./'));

What do You use as $filename ?

Does the created zip really contain data (have an adequate filesize) ?


file_write() - file helper - El Forum - 08-15-2009

[eluser]Bondie[/eluser]
yeh, it just messed up when i used ftp class as ascii, so changed it to auto, transfering the zip to a remote server, working fine now, thanks Tom Smile