diff options
author | admin <devnull@localhost> | 2006-10-02 04:38:50 +0200 |
---|---|---|
committer | admin <devnull@localhost> | 2006-10-02 04:38:50 +0200 |
commit | 78bc039b72695ab67a2d0d537b4c1f03d5d01b83 (patch) | |
tree | bdf94e457f8b3da4b886bcf4ed2db86f328caa80 | |
parent | e856ff49e44eec43a84123810e9672f4c92dcaa0 (diff) |
-rw-r--r-- | system/application/config/mimes.php | 3 | ||||
-rw-r--r-- | system/database/DB_utility.php | 141 |
2 files changed, 25 insertions, 119 deletions
diff --git a/system/application/config/mimes.php b/system/application/config/mimes.php index b09cc1963..de0a91752 100644 --- a/system/application/config/mimes.php +++ b/system/application/config/mimes.php @@ -39,6 +39,7 @@ $mimes = array( 'hqx' => 'application/mac-binhex40', 'dxr' => 'application/x-director', 'dvi' => 'application/x-dvi', 'gtar' => 'application/x-gtar', + 'gz' => 'application/x-gzip', 'php' => 'application/x-httpd-php', 'php4' => 'application/x-httpd-php', 'php3' => 'application/x-httpd-php', @@ -51,7 +52,7 @@ $mimes = array( 'hqx' => 'application/mac-binhex40', 'tgz' => 'application/x-tar', 'xhtml' => 'application/xhtml+xml', 'xht' => 'application/xhtml+xml', - 'zip' => array('application/zip', 'application/x-zip-compressed'), + 'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed'), 'mid' => 'audio/midi', 'midi' => 'audio/midi', 'mpga' => 'audio/mpeg', diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index e239d75e8..339baa8be 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -330,10 +330,8 @@ class CI_DB_utility { $prefs = array( 'tables' => array(), 'ignore' => array(), - 'format' => 'gzip', // gzip, zip, txt - 'action' => 'download', // download, archive, echo, return 'filename' => '', - 'filepath' => '', + 'format' => 'gzip', // gzip, zip, txt 'add_drop' => TRUE, 'add_insert' => TRUE, 'newline' => "\n" @@ -385,148 +383,55 @@ class CI_DB_utility { // ------------------------------------------------------ - // Set the filename if not provided - if ($prefs['filename'] == '') + // Set the filename if not provided - Only needed with Zip files + if ($prefs['filename'] == '' AND $prefs['format'] == 'zip') { $prefs['filename'] = (count($prefs['tables']) == 1) ? $prefs['tables'] : $this->db->database; $prefs['filename'] .= '_'.date('Y-m-d_H-i', time()); } // ------------------------------------------------------ - - // If we are archiving the export, does this filepath exist - // and resolve to a writable directory - if ($prefs['action'] == 'archive') + + // Grab the super object + $obj =& get_instance(); + + // Was a Gzip file requested? + if ($prefs['format'] == 'gzip') { - if ($prefs['filepath'] == '' OR ! is_writable($prefs['filepath'])) - { - if ($this->db->db_debug) - { - return $this->db->display_error('db_filepath_error'); - } - - $prefs['action'] = 'download'; - } + return gzencode($this->_backup($prefs)); } // ------------------------------------------------------ - // Are we returning the backup data? If so, we're done... - if ($prefs['action'] == 'return') + // Was a text file requested? + if ($prefs['format'] == 'txt') { return $this->_backup($prefs); } // ------------------------------------------------------ - - // Are we echoing the backup? If so, format the data and spit it at the screen... - if ($prefs['action'] == 'echo') - { - echo '<pre>'; - echo htmlspecialchars($this->_backup($prefs)); - echo '</pre>'; - - return TRUE; - } - - // ------------------------------------------------------ - // Are we archiving the data to the server? - if ($prefs['action'] == 'archive') + // Was a Zip file requested? + if ($prefs['format'] == 'zip') { - // Make sure the filepath has a trailing slash - if (ereg("/$", $prefs['filepath']) === FALSE) + // If they included the .zip file extension we'll remove it + if (preg_match("|.+?\.zip$|", $prefs['filename'])) { - $prefs['filepath'] .= '/'; + $prefs['filename'] = str_replace('.zip', '', $prefs['filename']); } - - // Assemble the path and tack on the file extension - $ext = array('gzip' => 'gz', 'zip' => 'zip', 'txt' => 'sql'); - $path = $prefs['filepath'].$prefs['filename'].$ext[$prefs['format']]; - - // Load the file helper - $obj =& get_instance(); - $obj->load->helper('file'); - // Write the file based on type - switch ($prefs['format']) + // Tack on the ".sql" file extension if needed + if ( ! preg_match("|.+?\.sql$|", $prefs['filename'])) { - case 'gzip' : - write_file($path, gzencode($this->_backup($prefs))); - return TRUE; - break; - case 'txt' : - write_file($path, $this->_backup($prefs)); - return TRUE; - break; - default : - $obj->load->library('zip'); - $obj->zip->add_data($prefs['filename'].'.sql', $this->_backup($prefs)); - $obj->zip->archive($path); - return TRUE; - break; + $prefs['filename'] .= '.sql'; } - - } - // ------------------------------------------------------ - - - // 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') - { + // Load the Zip class and output it $obj->load->library('zip'); - $obj->zip->add_data($prefs['filename'].'.sql', $this->_backup($prefs)); - $obj->zip->download($prefs['filename'].'.'.$ext[$prefs['format']]); - return TRUE; + $obj->zip->add_data($prefs['filename'], $this->_backup($prefs)); + return $obj->zip->get_zip(); } - - // 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']]; - - if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) - { - 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 - { - 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' : echo gzencode($this->_backup($prefs)); - break; - case 'txt' : echo $this->_backup($prefs); - break; - } - - return TRUE; } |