php - How to dump database backup file in computer's another disk and to network pc? -


i using code dump database backup file folder in htdocs named db_backup, , and option download backup file.

<?php function export_tables($host,$user,$pass,$name,  $tables=false, $backup_name=false ) {     $link = mysqli_connect($host,$user,$pass,$name);     // check connection     if (mysqli_connect_errno())   {   echo "failed connect mysql: " . mysqli_connect_error();   }      mysqli_select_db($link,$name);     mysqli_query($link,"set names 'utf8'");      //get of tables     if($tables === false)     {         $tables = array();         $result = mysqli_query($link,'show tables');         while($row = mysqli_fetch_row($result))         {             $tables[] = $row[0];         }     }     else     {         $tables = is_array($tables) ? $tables : explode(',',$tables);     }     $return='';     //cycle through     foreach($tables $table)     {         $result = mysqli_query($link,'select * `'.$table.'`');         $num_fields = mysqli_num_fields($result);          $row2 = mysqli_fetch_row(mysqli_query($link, 'show create table `'.$table.'`'));         $return.= "\n\n".$row2[1].";\n\n";          ($i = 0; $i < $num_fields; $i++)          {             $st_counter= 0;             while($row = mysqli_fetch_row($result))             {                 //create new command if when starts , after 100 command cycle                 if ($st_counter%100 == 0 || $st_counter == 0 )  {                     $return.= "\ninsert `".$table."` values";                 }                   $return.="\n(";                 for($j=0; $j<$num_fields; $j++)                  {                     $row[$j] = addslashes($row[$j]);                     $row[$j] = str_replace("\n","\\n",$row[$j]);                     if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }                     if ($j<($num_fields-1)) { $return.= ','; }                 }                 $return.=")";                   //create new command if when starts , after 100 command cycle (but detect 1 cycle earlier !)                 if ( ($st_counter+1)%100 == 0  && $st_counter != 0 )    {   $return.= ";";  }                 else                                                {   $return.= ",";  }                 //+++++++                 $st_counter = $st_counter +1 ;             }             //as cant detect while loop end, so, detect, if last command ends comma(,) replace semicolon(;)             if (substr($return, -1) == ',') {$return = substr($return, 0, -1). ';'; }         }         $return.="\n\n\n";     }      //save file     $backup_name = $backup_name ? $backup_name : $name."___(".date('h-i-s')."_".date('d-m-y').').sql';     file_put_contents('db_backup/'.$backup_name,$return);     echo 'success. download backup file: <a target="_blank" href="'.'db_backup/'.$backup_name.'">'.$backup_name.'</a>';  }  if (!empty($_get['delete_filee'])){ chdir(dirname(__file__));            if  (unlink($_get['delete_filee'])) {die('file_deleted');}      else                                {die("file doesnt exist");} } ?> 

executed by:

<?php                 include("../dbbackup_function.php");                 export_tables("localhost","root","password","isys");             ?> 

i know how save in disk in pc/server , in network pc.

for disk, tried:

file_put_contents('d:/db_backup/'.$backup_name,$return);         echo 'success. download backup file: <a target="_blank" href="'.'d:/db_backup/'.$backup_name.'">'.$backup_name.'</a>'; 

the dump works fine download doesn't. errors:

enter image description here

so how can fix download error this?

for network pc, tried:

file_put_contents('//devserver/users/administrator/downloads/test/'.$backup_name,$return);             echo 'success. download backup file: <a target="_blank" href="'.'//devserver/users/administrator/downloads/test/'.$backup_name.'">'.$backup_name.'</a>'; 

the dump errors:

warning: file_put_contents(//devserver/users/administrator/downloads/test/test___(03-25-01_12-11-2014).sql) [function.file-put-contents]: failed open stream: permission denied in e:\xampp\htdocs\sample\test2.php on line 71

while download errors object not found.

so how can access network pc? have credentials, don't know how thru code.

any appreciated.

when link file stored on local (or networked) drive make sure prepend path file://.

similar question @ how open pdf file located in local c drive


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -