From 9f8243b382329609fa24fe84928c8873b380d44c Mon Sep 17 00:00:00 2001
From: admin Permits you to add data to the Zip archive. The first parameter must contain the name you would like
-given to the file, the second parameter must contain the file data:$this->zip->add_data()
$name = 'my_bio.txt';
@@ -104,19 +104,7 @@ $data = 'I was born in an elevator...';
$this->zip->add_data($name, $data);
-
-If you would like to compress a file that exists somewhere on your server you will need to read the data before -passing it to the function:
- -
-$name = 'photo.jpg';
-$data = file_get_contents("/path/to/photo.jpg"); // Read the file's contents
-
-$this->zip->add_data($name, $data);
-
-
-
-You are allowed to have multiple calls to this function in order to +
You are allowed multiple calls to this function in order to add several files to your archive. Example:
@@ -134,8 +122,7 @@ $this->zip->add_data($name, $data);
$data = array(
'mydata1.txt' => 'A Data String!',
- 'mydata2.txt' => 'Another Data String!',
- 'photo.jpg' => file_get_contents("/path/to/photo.jpg")
+ 'mydata2.txt' => 'Another Data String!'
);
$this->zip->add_data($data);
@@ -163,6 +150,53 @@ using $this->zip->add_data(), but if you would like to create an empt
$this->zip->add_dir('myfolder'); // Creates a folder called "myfolder"
+
+$this->zip->read_file()
+
+Permits you to compress a file that already exists somewhere on your server. Supply a file path and the zip class will
+read it and add it to the archive:
+
+
+$path = '/path/to/photo.jpg';
+$this->zip->read_file($path);
+
+ // Download the file to your desktop. Name it "my_backup.zip"
+$this->zip->download('my_backup.zip');
+
+
+If you would like the Zip archive to maintain the directory structure the file is in, pass TRUE (boolean) in the
+second parameter. Example:
+
+
+
+$path = '/path/to/photo.jpg';
+$this->zip->read_file($path, TRUE);
+
+ // Download the file to your desktop. Name it "my_backup.zip"
+$this->zip->download('my_backup.zip');
+
+
+
In the above example, photo.jpg will be placed inside two folders: path/to/
+
+
+
+$this->zip->read_dir()
+
+Permits you to compress a folder (and its contents) that already exists somewhere on your server. Supply a file path to the
+directory and the zip class will recursively read it and recreate it as a Zip archive. All files contained within the
+supplied path will be encodes, as will any sub-folders contained within it. Example:
+
+
+$path = '/path/to/your/directory/';
+$this->zip->read_dir($path);
+
+ // Download the file to your desktop. Name it "my_backup.zip"
+$this->zip->download('my_backup.zip');
+
+
+
+
+
$this->zip->archive()
Writes the Zip-encoded file to a directory on your server. Submit a valid server path ending in the file name. Make sure the
@@ -213,8 +247,7 @@ $zip_file = $this->zip->get_zip();
$name = 'photo.jpg';
-$data = file_get_contents("/path/to/photo.jpg"); // Read the file's contents
-$this->zip->add_data($name, $data);
+$this->zip->read_file("/path/to/photo.jpg"); // Read the file's contents
$this->zip->download('myphotos.zip');
--
cgit v1.2.3-24-g4f1b