]]jkjjgdjffksdkdfdkasdashjgjdsadsadsadsadskdfgjdskfgj
במ12[aspddfasdasddsadsadadasdasdghjghjghjsadasbvxcvxcv;'
/
home2
/
kediapaper
/
public_html
/
Upload FileeE
HOME
<?php ob_start(); require_once("includes/dbsmain.inc.php"); /*********************** To create backup of website and database as well *****************/ /*********************** CODE CREATED AND DEVELOPED BY AMITABH KUMAR SINHA DATE:25:09:2013 *****************/ //1) Set execution time to 0 if in case your site is huge and will take much time for back-up as default execution time for PHP is 30 seconds. ini_set("max_execution_time", 0); ini_set('memory_limit', '256M'); //if ($_SERVER['HTTP_HOST'] == "localhost") { // define('LOCL_MDE', true); //} else { // define('LOCL_MDE', false); //} //if (LOCL_MDE) { //$host = "localhost"; //host name //$username = "root"; //username //$password = ""; // your password //$dbname = "tki_food"; // database name //} else { //$host = "localhost"; //host name //$username = "ei_tkifood"; //username //$password = "eFNH,L~KNE?R"; // your password //$dbname = "ei_tkifood"; // database name //} //4) We are going to save our backup in zip format so create an object of zip. $zip = new ZipArchive(); //5) Call the function backup_tables. backup_tables($ARR_CFGS["db_host"], $ARR_CFGS["db_user"], $ARR_CFGS["db_pass"], $ARR_CFGS["db_name"]); //6) Define the function backup_tables which will create a database sql file. /* backup the db OR just a table */ function backup_tables($host,$user,$pass,$name,$tables = '*'){ $link = mysqli_connect($host,$user,$pass); mysqli_select_db($name,$link); //get all of the tables if($tables == '*'){ $tables = array(); $result = mysqli_query('SHOW TABLES'); while($row = mysqli_fetch_row($result)){ $tables[] = $row[0]; } }else{ $tables = is_array($tables) ? $tables : explode(',',$tables); } //cycle through foreach($tables as $table){ $filename = $table.'.sql'; $handle = fopen($filename,'w'); $result = mysqli_query('SELECT * FROM '.$table); $num_fields = mysqli_num_fields($result); fwrite( $handle, 'DROP TABLE '.$table.';' ); $row2 = mysqli_fetch_row(mysqli_query('SHOW CREATE TABLE '.$table)); fwrite( $handle, "\n\n".$row2[1].";\n\n" ); for ($i = 0; $i < $num_fields; $i++){ while($row = mysqli_fetch_row($result)){ fwrite( $handle, 'INSERT INTO '.$table.' VALUES(' ); for($j=0; $j<$num_fields; $j++){ $row[$j] = addslashes($row[$j]); $row[$j] = ereg_replace("\n","\\n",$row[$j]); if (isset($row[$j])) { fwrite( $handle, '"'.$row[$j].'"' ) ; } else { fwrite( $handle, '""' ); } if ($j<($num_fields-1)) { fwrite( $handle, ',' ); } } fwrite( $handle, ");\n" ); } } fwrite( $handle, "\n\n\n" ); } //save file fclose($handle); } //7) Convert .sql file in .sql.zip file and remove the .sql file. if (glob("*.sql") != false){ $filecount = count(glob("*.sql")); $arr_file = glob("*.sql"); for($j=0;$j<$filecount;$j++){ $res = $zip->open($arr_file[$j].".zip", ZipArchive::CREATE); if ($res === TRUE){ $zip->addFile($arr_file[$j]); $zip->close(); unlink($arr_file[$j]); } } } //8) Now we have to get current folder name in which our php file is present. This is because when we have to move all folders and files from root directory to our zip. //get the current folder name-start $path = dirname($_SERVER['PHP_SELF']); $position = strrpos($path,'/') + 1; $folder_name = substr($path,$position); //get the current folder name-end //9) Create a name for zip file. I have created it based on today�s date so that we can easily find date of last backup. Also I have append �amitabh-� to a name of zip file which we use in next procedures. $zipname = date('Y/m/d'); $str = "amitabh-".$zipname.".zip"; $str = str_replace("/", "-", $str); //10) Add all files from current folder in newly created zip file. // open archive if ($zip->open($str, ZIPARCHIVE::CREATE) !== TRUE) { die ("Could not open archive"); } // initialize an iterator // pass it the directory to be processed $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("../$folder_name/")); // iterate over the directory // add each file found to the archive foreach ($iterator as $key=>$value) { if( strstr(realpath($key), "amitabh") == FALSE) { $zip->addFile(realpath($key), $key) or die ("ERROR: Could not add file: $key"); } } // close and save archive $zip->close(); if(glob("*.sql.zip") != false) { $filecount = count(glob("*.sql.zip")); $arr_file = glob("*.sql.zip"); for($j=0;$j<$filecount;$j++){ unlink($arr_file[$j]); } } //12) Now move a copy of our zip file to a direcotry which we have created in step 2. //get the array of zip files if(glob("*.zip") != false) { $arr_zip = glob("*.zip"); } //13) Delete a zip file from root directory as we moved it in another directory. for ($i=0; $i < count($delete_zip); $i++) { unlink($delete_zip[$i]); } //14) Below code will download the zip forcly.//////////////////////////////// header("Content-type: application/zip"); header("Content-Disposition: attachment; filename=$str"); header("Pragma: no-cache"); header("Expires: 0"); readfile("$str"); exit; ?>