⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 backup.php

📁 网络硬盘_支持1GB文件上传和续传_无错版
💻 PHP
📖 第 1 页 / 共 2 页
字号:
				$result = mysql_query('SELECT * FROM '.BACKTICKCHAR.$this->SelectedTables[$dbname][$t].BACKTICKCHAR);
				$rows[$t] = mysql_num_rows($result);
				if ($rows[$t] > 0) {
					$tabledatadumpline = '# dumping data for '.$dbname.'.'.$this->SelectedTables[$dbname][$t].LINE_TERMINATOR;
                    $this->Write2File($tabledatadumpline);
                    $alltablesdata.=$tabledatadumpline;
				}
				unset($fieldnames);
				for ($i = 0; $i < mysql_num_fields($result); $i++) {
					$fieldnames[] = mysql_field_name($result, $i);
				}
				if ($this->DataType==1) {
					$insertstatement = 'INSERT INTO '.BACKTICKCHAR.$this->SelectedTables[$dbname][$t].BACKTICKCHAR.' ('.BACKTICKCHAR.implode(BACKTICKCHAR.', '.BACKTICKCHAR, $fieldnames).BACKTICKCHAR.') VALUES (';
				} else {
					$insertstatement = 'INSERT INTO '.BACKTICKCHAR.$this->SelectedTables[$dbname][$t].BACKTICKCHAR.' VALUES (';
				}
				$thistableinserts = '';
				while ($row = mysql_fetch_array($result)) {
					unset($valuevalues);
					foreach ($fieldnames as $key => $val) {
						if ($row[$key] === null) {
							$valuevalues[] = 'NULL';
						} else {
							$valuevalues[] = QUOTECHAR.mysql_escape_string($row[$key]).QUOTECHAR;
						}
					}
					$thistableinserts .= $insertstatement.implode(', ', $valuevalues).');'.LINE_TERMINATOR;

					if (strlen($thistableinserts) >= BUFFER_SIZE) {
                        $alltablesdata.=$thistableinserts;
                        $this->Write2File($thistableinserts);
						$thistableinserts = '';
					}
				}
                $alltablesdata.=$thistableinserts.LINE_TERMINATOR.LINE_TERMINATOR;
                $this->Write2File($thistableinserts.LINE_TERMINATOR.LINE_TERMINATOR);
			}
		}
        return  $alltablesdata;
    }
    function OpenFile()
    {
        if(is_resource($this->fp)) return true;

        if(!is_writable($this->BackupDir)) die($this->backupabsolutepath." is not writable,exit");
        if($this->GZ_enabled)
        $this->fp=@gzopen($this->BackupDir.'/'.$this->tempbackupfilename, 'wb');
        else
        $this->fp=@fopen($this->BackupDir.'/'.$this->tempbackupfilename, 'wb');

    }
    function Write2File($content)
    {
         if($this->GZ_enabled)
         gzwrite($this->fp, $content, strlen($content));
         else
         fwrite($this->fp, $content, strlen($content));
    }
    function CloseFile()
    {
        if($this->GZ_enabled)
        gzclose($this->fp);
        else
        fclose($this->fp);
    }
    function FormattedTimeRemaining($seconds, $precision=1)
    {
	if ($seconds > 86400) {
		return $this->number_format($seconds / 86400, $precision).' days';
	} elseif ($seconds > 3600) {
		return $this->number_format($seconds / 3600, $precision).' hours';
	} elseif ($seconds > 60) {
		return $this->number_format($seconds / 60, $precision).' minutes';
	}
	return $this->number_format($seconds, $precision).' seconds';
    }

    function FileSizeNiceDisplay($filesize, $precision=2)
    {
	if ($filesize < 1000) {
		$sizeunit  = 'bytes';
		$precision = 0;
	} else {
		$filesize /= 1024;
		$sizeunit = 'kB';
	}
	if ($filesize >= 1000) {
		$filesize /= 1024;
		$sizeunit = 'MB';
	}
	if ($filesize >= 1000) {
		$filesize /= 1024;
		$sizeunit = 'GB';
	}
	return number_format($filesize, $precision).' '.$sizeunit;
    }

    function OutputInformation($text='')
    {
    global $TPL;
		if ($this->debug&&$text) {
			$TPL[body].=$text.'<br>';
			flush();
		}
    }
    function EmailAttachment($from, $to, $subject, $textbody, &$attachmentdata, $attachmentfilename) {
	$boundary = '_NextPart_'.time().'_'.md5($attachmentdata).'_';

	$textheaders  = '--'.$boundary."\n";
	$textheaders .= 'Content-Type: text/plain; format=flowed; charset="iso-8859-1"'."\n";
	$textheaders .= 'Content-Transfer-Encoding: 7bit'."\n\n";

	$attachmentheaders  = '--'.$boundary."\n";
	$attachmentheaders .= 'Content-Type: application/octet-stream; name="'.$attachmentfilename.'"'."\n";
	$attachmentheaders .= 'Content-Transfer-Encoding: base64'."\n";
	$attachmentheaders .= 'Content-Disposition: attachment; filename="'.$attachmentfilename.'"'."\n\n";

	$headers[] = 'From: '.$from;
	$headers[] = 'Content-Type: multipart/mixed; boundary="'.$boundary.'"';

	return mail($to, $subject, $textheaders.ereg_replace("[\x80-\xFF]", '?', $textbody)."\n\n".$attachmentheaders.wordwrap(base64_encode($attachmentdata), 76, "\n", true)."\n\n".'--'.$boundary."--\n\n", implode("\r\n", $headers));
    }
    function getmicrotime() {
		list($usec, $sec) = explode(' ', microtime());
		return ((float) $usec + (float) $sec);
	}
}
function readSqlFile($sqlfile)
{
global  $cfg,$table_prefix,$input;
    $sql_query='';
    $ext=strtolower(strrchr(basename($sqlfile),'.'));
    if($ext=='.sql')
    {
        $sql_query = @fread(@fopen($sqlfile, 'r'), @filesize($sqlfile));
    }
    else
    {
        $zp = gzopen($sqlfile, "r");
        if ($zp)
        while (!gzeof($zp))
        {
           $sql_query .= gzgets ($zp, 4096) ;
        }
    }

	$sql_query = remove_remarks($sql_query);
	$sql_query = split_sql_file($sql_query, $delimiter_basic=';');

    return  $sql_query;
}
function remove_comments(&$output)
{
	$lines = explode("\n", $output);
	$output = "";

	// try to keep mem. use down
	$linecount = count($lines);

	$in_comment = false;
	for($i = 0; $i < $linecount; $i++)
	{
		if( preg_match("/^\/\*/", preg_quote($lines[$i])) )
		{
			$in_comment = true;
		}

		if( !$in_comment )
		{
			$output .= $lines[$i] . "\n";
		}

		if( preg_match("/\*\/$/", preg_quote($lines[$i])) )
		{
			$in_comment = false;
		}
	}

	unset($lines);
	return $output;
}

//
// remove_remarks will strip the sql comment lines out of an uploaded sql file
//
function remove_remarks($sql)
{
	$lines = explode("\n", $sql);

	// try to keep mem. use down
	$sql = "";

	$linecount = count($lines);
	$output = "";

	for ($i = 0; $i < $linecount; $i++)
	{
		if (($i != ($linecount - 1)) || (strlen($lines[$i]) > 0))
		{
			if ($lines[$i][0] != "#")
			{
				$output .= $lines[$i] . "\n";
			}
			else
			{
				$output .= "\n";
			}
			// Trading a bit of speed for lower mem. use here.
			$lines[$i] = "";
		}
	}

	return $output;

}

//
// split_sql_file will split an uploaded sql file into single sql statements.
// Note: expects trim() to have already been run on $sql.
//
function split_sql_file($sql, $delimiter)
{
	// Split up our string into "possible" SQL statements.
	$tokens = explode($delimiter, $sql);

	// try to save mem.
	$sql = "";
	$output = array();

	// we don't actually care about the matches preg gives us.
	$matches = array();

	// this is faster than calling count($oktens) every time thru the loop.
	$token_count = count($tokens);
	for ($i = 0; $i < $token_count; $i++)
	{
		// Don't wanna add an empty string as the last thing in the array.
		if (($i != ($token_count - 1)) || (strlen($tokens[$i] > 0)))
		{
			// This is the total number of single quotes in the token.
			$total_quotes = preg_match_all("/'/", $tokens[$i], $matches);
			// Counts single quotes that are preceded by an odd number of backslashes,
			// which means they're escaped quotes.
			$escaped_quotes = preg_match_all("/(?<!\\\\)(\\\\\\\\)*\\\\'/", $tokens[$i], $matches);

			$unescaped_quotes = $total_quotes - $escaped_quotes;

			// If the number of unescaped quotes is even, then the delimiter did NOT occur inside a string literal.
			if (($unescaped_quotes % 2) == 0)
			{
				// It's a complete sql statement.
				$output[] = $tokens[$i];
				// save memory.
				$tokens[$i] = "";
			}
			else
			{
				// incomplete sql statement. keep adding tokens until we have a complete one.
				// $temp will hold what we have so far.
				$temp = $tokens[$i] . $delimiter;
				// save memory..
				$tokens[$i] = "";

				// Do we have a complete statement yet?
				$complete_stmt = false;

				for ($j = $i + 1; (!$complete_stmt && ($j < $token_count)); $j++)
				{
					// This is the total number of single quotes in the token.
					$total_quotes = preg_match_all("/'/", $tokens[$j], $matches);
					// Counts single quotes that are preceded by an odd number of backslashes,
					// which means they're escaped quotes.
					$escaped_quotes = preg_match_all("/(?<!\\\\)(\\\\\\\\)*\\\\'/", $tokens[$j], $matches);

					$unescaped_quotes = $total_quotes - $escaped_quotes;

					if (($unescaped_quotes % 2) == 1)
					{
						// odd number of unescaped quotes. In combination with the previous incomplete
						// statement(s), we now have a complete statement. (2 odds always make an even)
						$output[] = $temp . $tokens[$j];

						// save memory.
						$tokens[$j] = "";
						$temp = "";

						// exit the loop.
						$complete_stmt = true;
						// make sure the outer loop continues at the right point.
						$i = $j;
					}
					else
					{
						// even number of unescaped quotes. We still don't have a complete statement.
						// (1 odd and 1 even always make an odd)
						$temp .= $tokens[$j] . $delimiter;
						// save memory.
						$tokens[$j] = "";
					}

				} // for..
			} // else
		}
	}

	return $output;
}
?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -