Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 13
  1. #1
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,773

    classe per effettuare il backup , che viene stampata a video

    salve ragazzi e buona domenica , avrei bisognio del vostro prezziosissimo aiuto, ho un problema con una classe che effettua il backup del database, sarebbe a dire che non mi crea il download , bensi' mi stampa tutto a video. Il problema potrebbe trattarsi di una questione di header comunque confido in un vosttro aiuto posto la classe .....
    Codice PHP:

            
    class backup {
            
            var 
    $struct_only false;
            var 
    $save_on_server true;
            var 
    $createtable true;
            var 
    $compress true;
            var 
    $filename "";
            var 
    $ext "";
            var 
    $useragent "";
            var 
    $newline;
            
            function 
    backup($struct_only false $save_on_server true $createtable true ,$compress true$filename "" )
            {   
                
    $this->struct_only $struct_only;
                
    $this->save_on_server $save_on_server;
                
    $this->createtable $createtable;
                
    $this->compress $compress;
                
    $this->filename $filename;
                
    $this->useragent trim(substr($_SERVER['HTTP_USER_AGENT'], 060));
                
    $this->newline $this->_define_newline();
            }

            function 
    perform_backup($filename,$ext){
                
    ob_start();
                
    header('Content-Type: ' $this->_get_mime_type());
                
    header('Expires: ' gmdate('D, d M Y H:i:s') . ' GMT');
                if( 
    $this->_get_browser_type() == 'IE' ){
                
    header('Content-Disposition: inline;  filename="' $filename '.' $ext '"' );
                
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0' );
                
    header('Pragma: public' );
                }else{
                
    header('Content-Disposition: attachment; filename="' $filename '.' $ext '"' );
                
    header('Pragma: no-cache' );
                }
                
    ob_end_clean(); 
        }

            function 
    _get_def($tablename)
            {
                global 
    $dbcore ;
                
    $def "";
                
    $def .= "#------------------------------------------" $this->newline;
                
    $def .= "# Table definition for $tablename$this->newline;
                
    $def .= "#------------------------------------------" $this->newline;
                
    $def .= "DROP TABLE IF EXISTS $tablename;" $this->newline $this->newline;
                
    $def .= "CREATE TABLE $tablename (" $this->newline;
                
    $result $dbcore->query"SHOW FIELDS FROM `".$dbcore->escape($tablename)."`" ) or die( "Table $tablename not existing in database" );
                while ( 
    $row $dbcore->fetch_array($result) )
                {
                    
                     
    $def .= " ".$row["Field"]."`".$row["Type"];   
                    if(
    $row["Null"] != "YES"){
                       
    $def .= " NOT NULL";
                    }
                    if(
    $row["Default"] != ""){
                        if ( 
    $row["Default"] == "CURRENT_TIMESTAMP" ){
                             
    $def .= " default CURRENT_TIMESTAMP";
                            }else{
                                
    $def .= " default $row[Default]";
                            }
                        }
                    if(
    $row['Extra'] != "" ){
                       
    $def .= $row[Extra]";
                       }
                       
    $def .= ",$this->newline";
                    }
                       
    $def ereg_replace",$this->newline$"""$def);
                
    $result $dbcore->query("SHOW KEYS FROM `".$tablename."`" );
                while (
    $row $dbcore->fetch_array($result))
                {
                    
    $kname $row['Key_name'];
                    if ( (
    $kname != "PRIMARY") && ($row['Non_unique'] == 0) ) $kname "UNIQUE|$kname";
                    if ( !isset(
    $index[$kname]) ) $index[$kname] = array();
                    
    $index[$kname][] = $row['Column_name'];
                }
                while (list(
    $x$columns) = @each($index) )
                {
                    
    $def .= ",$this->newline";
                    if ( 
    $x == "PRIMARY" $def .= "   PRIMARY KEY (" implode$columns", " ) . ")";
                    else if ( 
    substr($x06) == "UNIQUE" $def .= "   UNIQUE " substr$x) . " (" implode$columns", " ) . ")";
                    else  
    $def .= "   KEY $x (" implode$columns", " ) . ")";
                }
                
    $def .= "$this->newline);";

                return (
    stripslashes($def) );
            }

            function 
    _get_content$tablename )
            {
                global 
    $dbcore ;
                
    $content "";
                
    $result $dbcore->query("SELECT * FROM  `".$tablename."`" );
                if (
    $dbcore->num_rows($result) > 0)
                {
                    
    $content .= "#------------------------------------------" $this->newline;
                    
    $content .= "# Data inserts for $tablename$this->newline;
                    
    $content .= "#------------------------------------------" $this->newline;
                }
                while (
    $row $dbcore->fetch_row($result))
                {
                    
    $insert "INSERT INTO `".$tablename."` VALUES (";

                    for ( 
    $j 0$j $dbcore->num_fields($result); $j++ )
                    {
                        if ( !isset(
    $row[$j]) ) $insert .= "NULL,";
                        elseif ( 
    $row[$j] != "" $insert .= "'" addslashes$row[$j] ) . "',";
                        else  
    $insert .= "'',";
                    }

                    
    $insert ereg_replace",$"""$insert );
                    
    $insert .= ");$this->newline";
                    
    $content .= $insert;
                }
              
                return 
    $content $this->newline;
            }
            function 
    _backup()
            {
                global 
    $dbcore ;
                
    $i 0;
                
    $now gmdate'D, d M Y H:i:s' ) . ' GMT';
                
    $newfile "";
                
    $newfile .= "#########################################" $this->newline;
                
    $newfile .= "# rcSupport Backup System" $this->newline;
                
    $newfile .= "# Database:"DATABASE_NAME  $this->newline;
                
    $newfile .= "# Date: $now$this->newline;
                
    $newfile .= "#########################################" $this->newline $this->newline;
                
    $result $dbcore->query"SHOW TABLES FROM `".$dbcore->escape(DATABASE_NAME)."`" );
                while (list(
    $table) = $dbcore->fetch_row($result))
                {
                    if ( 
    $this->createtable ){
                          
    $newfile .= $this->_get_def($table);
                          
    $newfile .= "$this->newline";
                          }
                    if ( !
    $this->struct_only ){
                           
    $newfile .= $this->_get_content($table );
                          
    $newfile .= "$this->newline";
                    }
                    
    $i++;
                }
                 
    $this->_out($newfile);
                return 
    true ;
            }

            function 
    _out$dump )
            {
             if(empty(
    $this->filename) ){
             
    $this->filename DATABASE_NAME .".".date("d")."_".date("M")."_".date("Y")."_".date("H")."_".date("i")."_".date("s");
             }else{
             
    $this->filename $filename .".".date("d")."_".date("M")."_".date("Y")."_".date("H")."_".date("i")."_".date("s");
             } 
             if(
    $this->compress  && extension_loaded("zlib")) {
             
    $this->ext "sql.gz";
             }else{
             
    $this->ext "sql";
             }
              if(
    $this->save_on_server) {
              
    $dir "./includes/";
              
    $files "Backup";
              if(!
    is_dir($dir.$files))
              {
                 
    mkdir($dir $files 0777);  
                 
    chmod($dir $files 0777); 
              }
              
    $handle fopen($dir $files ."/" $this->filename .'.'$this->ext"wb" );
              if(
    $handle){
                 if(
    $this->compress){
                        
    $gzbackupData "\x1f\x8b\x08\x00\x00\x00\x00\x00" substr(gzcompress($dump9), 0, -) . pack('V'crc32($dump)) . pack('V'strlen($dump));
                        
    fwrite$handle$gzbackupData );
                 }else{
                        
    fwrite($handle$dump );
                 }
                        
    fclose($handle);
              }          
              }
                
                 if(
    $this->compress && extension_loaded("zlib"))
                 {
                        
    set_time_limit(0); 
                        
    ob_start(); 
                        
                        
    $gzbackupData "\x1f\x8b\x08\x00\x00\x00\x00\x00" substr(gzcompress($dump9), 0, -) . pack('V'crc32($dump)) . pack('V'strlen($dump));
                        echo 
    $gzbackupData;
                 }else{  
                          echo 
    $dump 

                 }
            
            
    $this->perform_backup($this->filename,$this->ext);
             return 
    true 
            
            }





            function 
    _define_newline()
            {
                
    $unewline "\r\n";

                if ( 
    strstr(strtolower($this->useragent), 'win') )
                {
                  
    $unewline "\r\n";
                }else if ( 
    strstr(strtolower($this->useragent), 'mac') )
                {
                  
    $unewline "\r";
                }else{
                  
    $unewline "\n";
                }
                  return 
    $unewline;
            }

            function 
    _get_browser_type()
            {
                
    $USER_BROWSER_AGENT "";

                if ( 
    ereg('OPERA(/| )([0-9].[0-9]{1,2})'strtoupper($this->useragent), $log_version) )
                {
                  
    $USER_BROWSER_AGENT 'OPERA';
                }
                else if ( 
    ereg('MSIE ([0-9].[0-9]{1,2})'strtoupper($this->useragent), $log_version) )
                {
                  
    $USER_BROWSER_AGENT 'IE';
                }
                else if ( 
    ereg('OMNIWEB/([0-9].[0-9]{1,2})'strtoupper($this->useragent), $log_version) )
                {
                  
    $USER_BROWSER_AGENT 'OMNIWEB';
                }
                else if ( 
    ereg('MOZILLA/([0-9].[0-9]{1,2})'strtoupper($this->useragent), $log_version) )
                {
                  
    $USER_BROWSER_AGENT 'MOZILLA';
                }
                else if ( 
    ereg('KONQUEROR/([0-9].[0-9]{1,2})'strtoupper($this->useragent), $log_version) )
                {
                  
    $USER_BROWSER_AGENT 'KONQUEROR';
                }else{
                  
    $USER_BROWSER_AGENT 'OTHER';
                }
                return 
    $USER_BROWSER_AGENT;
            }

            function 
    _get_mime_type()
            {
                
    $USER_BROWSER_AGENT $this->_get_browser_type();

                
    $mime_type = ( $USER_BROWSER_AGENT == 'IE' || $USER_BROWSER_AGENT == 'OPERA' ) ? 'application/octetstream' 'application/octet-stream';
                return 
    $mime_type;
            }

        } 
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  2. #2
    Ti suggerisco di iniziare leggendo il manuale ufficiale:

    http://www.php.net/header Example #1 Download dialog

  3. #3
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,773
    ciao Filippo grazie , comunque ho letto la tua knowldgebase sugli header , molto utile e se da li ho capito bene , il primo otput che riceve ilk browser sono gli header , comunque provo a leggere sul sito ufficiale grazie
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  4. #4
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,773
    io uso un template engine : Smarty template , adesso l errore che mi da , mi appare su uno dei files compilati da smarty , quindi il problema potrebbe essere dentro smarty?
    codice:
    Warning: Cannot modify header information - headers already sent by (output started at C:\Programmi\Apache Software Foundation\Apache2.2\htdocs\supp\includes\Smarty\templates_c\%%CE^CE4^CE42039A%%cpheader.tpl.php:7 ) in C:\Programmi\Apache Software Foundation\Apache2.2\htdocs\supp\includes\functions_backup.php on line 48
    
    Warning: Cannot modify header information - headers already sent by (output started at C:\Programmi\Apache Software Foundation\Apache2.2\htdocs\supp\includes\Smarty\templates_c\%%CE^CE4^CE42039A%%cpheader.tpl.php:7 ) in C:\Programmi\Apache Software Foundation\Apache2.2\htdocs\supp\includes\functions_backup.php on line 50
    
    Warning: Cannot modify header information - headers already sent by (output started at C:\Programmi\Apache Software Foundation\Apache2.2\htdocs\supp\includes\Smarty\templates_c\%%CE^CE4^CE42039A%%cpheader.tpl.php:7 ) in C:\Programmi\Apache Software Foundation\Apache2.2\htdocs\supp\includes\functions_backup.php on line 51
    
    Warning: Cannot modify header information - headers already sent by (output started at C:\Programmi\Apache Software Foundation\Apache2.2\htdocs\supp\includes\Smarty\templates_c\%%CE^CE4^CE42039A%%cpheader.tpl.php:7 ) in C:\Programmi\Apache Software Foundation\Apache2.2\htdocs\supp\includes\functions_backup.php on line 52
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  5. #5
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,773
    buon giorno a tutti , ho guardato nel sito ufficiale di php in più ho dato un occhiata al files di phpMyAdmin export.php , dovrebbe essere corretta , ma non mi funziona perche ? dove toppo ?

    Codice PHP:

            
    function _out$dump )
            {
             if(empty(
    $this->filename) ){
             
    $this->filename DATABASE_NAME .".".date("d")."_".date("M")."_".date("Y")."_".date("H")."_".date("i")."_".date("s");
             }else{
             
    $this->filename $filename .".".date("d")."_".date("M")."_".date("Y")."_".date("H")."_".date("i")."_".date("s");
             } 
             if(
    $this->compress  && extension_loaded("zlib")) {
             
    $this->ext "sql.gz";
             
    $this->content_encoding 'x-gzip';
             
    $this->mime_type 'application/x-gzip';
             }else{
             
    $this->ext "sql";
             
    $this->content_encoding '';
             
    $this->mime_type 'text/x-sql';
             }
              if(
    $this->save_on_server) {
              
    $dir "./includes/";
              
    $files "Backup";
              if(!
    is_dir($dir.$files))
              {
                 
    mkdir($dir $files 0777);  
                 
    chmod($dir $files 0777); 
              }
              
    $handle fopen($dir $files ."/" $this->filename .'.'$this->ext"wb" );
              if(
    $handle){
                 if(
    $this->compress){
                        
    $gzbackupData "\x1f\x8b\x08\x00\x00\x00\x00\x00" substr(gzcompress($dump9), 0, -) . pack('V'crc32($dump)) . pack('V'strlen($dump));
                        
    fwrite$handle$gzbackupData );
                 }else{
                        
    fwrite($handle$dump );
                 }
                        
    fclose($handle);
              }          
              }
                
                 
    ob_start();    
                 if(
    $this->compress && extension_loaded("zlib"))
                 {  
                 
    $this->perform_backup($this->filename,$this->ext$this->content_encoding ,$this->mime_type);
                 
    $dump ob_get_contents();
                        
    $gzbackupData "\x1f\x8b\x08\x00\x00\x00\x00\x00" substr(gzcompress($dump9), 0, -) . pack('V'crc32($dump)) . pack('V'strlen($dump));
                        echo 
    $gzbackupData;
                 }else{  
                 
    $this->perform_backup($this->filename,$this->ext$this->content_encoding ,$this->mime_type);
                 
    $dump ob_get_contents();
                 echo 
    $dump;
                 }
    ob_end_clean();
            }

            function 
    perform_backup($filename $ext $content_encoding $mime_type)
            {
            if (!empty(
    $content_encoding)) {
            
    header('Content-Encoding: ' $content_encoding);
            }
            
    header('Content-Type: ' $mime_type);
            
    header('Expires: ' gmdate('D, d M Y H:i:s') . ' GMT');
            
    // lem9 & loic1: IE need specific headers
            
    if ($this->_get_browser_type() == 'IE') {
            
    header('Content-Disposition: inline;  filename="' $filename '.' $ext '"');
            
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
            
    header('Pragma: public');
            } else {
            
    header('Content-Disposition: attachment;  filename="' $filename '.' $ext '"');
            
    header('Pragma: no-cache');
            }
            
    readfile('"' $filename '.' $ext '"');
            } 
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  6. #6
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,773
    salve qualcuno mi potrebbe dare una mano perfavore
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  7. #7
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,773
    buon giorno mi potreste dare una mano per favore
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  8. #8
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,773
    salve ragazzi per la terz volta vi richiedo aiuto cortesemente mi potreste dire dov e l errore grazie confido in voi
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  9. #9
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,773
    mi date una mano perfavore
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  10. #10
    Utente di HTML.it L'avatar di dottwatson
    Registrato dal
    Feb 2007
    Messaggi
    3,012
    come implementi la classe?

    cosa c'entra phpMyAdmin?

    per poterla far funzionare correttamente quella classe dovresti inserirla in una pagina php dove c'è lei e solo lei, o la sua chiamata con tutte le sue opzioni che desideri (es. backup.php)

    e richiamarla così

    codice:
    scarica
    Non sempre essere l'ultimo è un male... almeno non devi guardarti le spalle

    il mio profilo su PHPClasses e il mio blog laboweb

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.