function restoreDBFromBackup() { makeRed("Restore Database? WARNING: This will drop all tables and restore data to last backup!"); echo "(Y/N): "; $data = FOPEN("php://stdin", "rb"); $input = ''; while (1 == 1) { $chunk = FREAD($data, 1); if ($chunk == "\n" || $chunk == "\r") { break; } $input .= $chunk; } FCLOSE($data); if (strtolower(@$input) == 'y') { echo "Getting Credentials from application.ini...\n"; $application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini'); $bootstrap = $application->getBootstrap(); $options = $bootstrap->getOptions(); $db = $options['resources']['db']['params']; echo "Database Restoring. Please be patient, this could take a while..."; sleep(1); echo "."; sleep(1); echo "."; sleep(1); echo "."; echo "\n"; exec("mysql -u " . $db['username'] . " -p" . $db['password'] . " " . $db['dbname'] . " < " . APPLICATION_PATH . "/../data/dbbackup.sql", $output); makeGreen("DONE!"); echo "\n\n"; } else { echo "Operation Cancelled.\n"; } }
function send_file($name) { OB_END_CLEAN(); $path = $name; //"../temp/".$name; if (!IS_FILE($path) or CONNECTION_STATUS() != 0) { return FALSE; } HEADER("Cache-Control: no-store, no-cache, must-revalidate"); HEADER("Cache-Control: post-check=0, pre-check=0", FALSE); HEADER("Pragma: no-cache"); HEADER("Expires: " . GMDATE("D, d M Y H:i:s", MKTIME(DATE("H") + 2, DATE("i"), DATE("s"), DATE("m"), DATE("d"), DATE("Y"))) . " GMT"); HEADER("Last-Modified: " . GMDATE("D, d M Y H:i:s") . " GMT"); HEADER("Content-Type: application/octet-stream"); HEADER("Content-Length: " . (string) FILESIZE($path)); HEADER("Content-Disposition: inline; filename={$name}"); HEADER("Content-Transfer-Encoding: binary\n"); if ($file = FOPEN($path, 'rb')) { while (!FEOF($file) and CONNECTION_STATUS() == 0) { print FREAD($file, 1024 * 8); FLUSH(); } FCLOSE($file); } return CONNECTION_STATUS() == 0 and !CONNECTION_ABORTED(); }