From 0f8015fcdc4eb7a2bedc6a04548e588b39914c60 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 1 Oct 2006 22:08:34 +0000 Subject: --- system/database/DB_utility.php | 81 +++++++++++++++++--------------------- system/libraries/Zip.php | 6 +-- user_guide/database/utilities.html | 6 --- user_guide/general/changelog.html | 1 + 4 files changed, 41 insertions(+), 53 deletions(-) diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 2748a4407..e239d75e8 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -460,10 +460,9 @@ class CI_DB_utility { return TRUE; break; default : - require BASEPATH.'libraries/Zip.php'; - $zip = new Zip; - $zip->add_file($this->_backup($prefs), $prefs['filename'].'.sql'); - write_file($path, $zip->output_zipfile()); + $obj->load->library('zip'); + $obj->zip->add_data($prefs['filename'].'.sql', $this->_backup($prefs)); + $obj->zip->archive($path); return TRUE; break; } @@ -472,65 +471,59 @@ class CI_DB_utility { // ------------------------------------------------------ - // Set the mime type used in the server header - switch ($prefs['format']) - { - case 'zip' : $mime = 'application/x-zip'; - break; - case 'gzip' : $mime = 'application/x-gzip'; - break; - default : - if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE") || strstr($_SERVER['HTTP_USER_AGENT'], "OPERA")) - { - $mime = 'application/octetstream'; - } - else - { - $mime = 'application/octet-stream'; - } - break; - } // Grab the super object $obj =& get_instance(); // Remap the file extensions $ext = array('gzip' => 'gz', 'zip' => 'zip', 'txt' => 'sql'); + + // Is a Zip file requested? + if ($prefs['format'] == 'zip') + { + $obj->load->library('zip'); + $obj->zip->add_data($prefs['filename'].'.sql', $this->_backup($prefs)); + $obj->zip->download($prefs['filename'].'.'.$ext[$prefs['format']]); + return TRUE; + } + + + // Set the mime type + switch ($prefs['format']) + { + case 'gzip' : $mime = 'application/x-gzip'; + break; + default : $mime = (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE") || strstr($_SERVER['HTTP_USER_AGENT'], "OPERA")) ? 'application/octetstream' : 'application/octet-stream'; + break; + } + + $filename = $prefs['filename'].'.sql.'.$ext[$prefs['format']]; - // Send headers if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) { - $obj->output->set_header('Content-Type: '.$mime); - $obj->output->set_header('Content-Disposition: inline; filename="'.$prefs['filename'].'.'.$ext[$prefs['format']].'"'); - $obj->output->set_header('Content-Transfer-Encoding: binary'); - $obj->output->set_header('Expires: 0'); - $obj->output->set_header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); - $obj->output->set_header('Pragma: public'); + header('Content-Type: '.$mime); + header('Content-Disposition: inline; filename="'.$filename.'"'); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header("Content-Transfer-Encoding: binary"); + header('Pragma: public'); } else { - $obj->output->set_header('Content-Type: '.$mime); - $obj->output->set_header('Content-Disposition: attachment; filename="'.$prefs['filename'].'.'.$ext[$prefs['format']].'"'); - $obj->output->set_header('Content-Transfer-Encoding: binary'); - $obj->output->set_header('Expires: 0'); - $obj->output->set_header('Pragma: no-cache'); + header('Content-Type: '.$mime); + header('Content-Disposition: attachment; filename="'.$filename.'"'); + header("Content-Transfer-Encoding: binary"); + header('Expires: 0'); + header('Pragma: no-cache'); } - // Write the file based on type switch ($prefs['format']) { - case 'gzip' : $obj->output->set_output(gzencode($this->_backup($prefs))); + case 'gzip' : echo gzencode($this->_backup($prefs)); break; - case 'txt' : $obj->output->set_output($this->_backup($prefs)); + case 'txt' : echo $this->_backup($prefs); break; - default : - require BASEPATH.'libraries/Zip.php'; - - $zip = new Zip; - $zip->add_file($this->_backup($prefs), $prefs['filename'].'.sql'); - $obj->output->set_output($zip->output_zipfile()); - break; } return TRUE; diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index a11699956..218388314 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -227,7 +227,7 @@ class CI_Zip { // -------------------------------------------------------------------- /** - * Write File + * Write File to the specified direcotry * * Lets you write a file * @@ -236,9 +236,9 @@ class CI_Zip { * @param string the data to be encoded * @return bool */ - function write_zip($filepath) + function archive($filepath) { - if ( ! ($fp = fopen($filepath, "wb"))) + if ( ! ($fp = @fopen($filepath, "wb"))) { return FALSE; } diff --git a/user_guide/database/utilities.html b/user_guide/database/utilities.html index 3efa04f1d..cbd8be784 100644 --- a/user_guide/database/utilities.html +++ b/user_guide/database/utilities.html @@ -274,12 +274,6 @@ $this->dbutil->backup($prefs); -

VERY IMPORTANT: If you are using the download action to send the file to your desktop, -DO NOT display any data in the controller in which you are triggering the backup. Since Code Igniter buffers all output, any data -sent to the browser will be included in your export file. This issue ONLY applies to downloads. If you are using any other action -you can display data in your controller.

- -

Description of Backup Preferences

diff --git a/user_guide/general/changelog.html b/user_guide/general/changelog.html index aab14d516..3f991e077 100644 --- a/user_guide/general/changelog.html +++ b/user_guide/general/changelog.html @@ -78,6 +78,7 @@ Change Log
  • Added $query->field_names() function
  • Added $this->db->platform() function
  • Added "is_numeric" to validation
  • +
  • Added two more protocols to the URI handler to make it more reliable when the $config['uri_protocol'] item is set to AUTO.
  • Deprecated "init" folder. Initialization happens automatically now. Please see documentation.
  • Deprecated $this->db->field_names() USE $this->db->list_fields()
  • -- cgit v1.2.3-24-g4f1b