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

📄 upgrade.php

📁 网络硬盘_支持1GB文件上传和续传_无错版
💻 PHP
📖 第 1 页 / 共 2 页
字号:
    }
    function debug($text)
    {
        if($this->debug) echo $text;
    }
}
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;
}
class unzipfile
{
	var $zipname;

	function unzipfile($zipname)
	{
		$this->zipname = $zipname;
	}

	function extract($to)
	{
        if($to=='') $to='.';
        $fp = @fopen($this->zipname, "rb");

		@fseek($fp, filesize($this->zipname)-18);

		$centralDir = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', @fread($fp, 18));
        //print_r($centralDir);
		$pos = $centralDir['offset'];

		for ($i = 0, $extracted = 0; $i < $centralDir['entries']; $i++) {

			@rewind($fp);
			@fseek($fp, $pos);

			$data = unpack('Vid', @fread($fp, 4));
			if ($data['id'] != 0x02014b50)
				return -1;

			$fileHeader = unpack('vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', @fread($fp, 42));

			$fileHeader['filename'] = fread($fp, $fileHeader['filename_len']);
			$fileHeader['extra'] = ($fileHeader['extra_len'] > 0) ? fread($fp, $fileHeader['extra_len']) : '';
			$fileHeader['comment'] = ($fileHeader['comment_len'] > 0) ? fread($fp, $fileHeader['comment_len']) : '';

			$isDirectory = 0;
			if (substr($fileHeader['filename'], -1) == '/')
				$isDirectory = 1;

			$fileHeader['mtime'] = $this->toUnixTimeStamp($fileHeader['mdate'], $fileHeader['mtime']);

			$pos = ftell($fp);

			@rewind($fp);
			@fseek($fp, $fileHeader['offset']);

			// ----- File entry
			$data = unpack('Vid', @fread($fp, 4));
			if ($data['id'] != 0x04034b50)
				return -1;

			$fileHeader = unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', @fread($fp, 26));

			$fileHeader['filename'] = fread($fp, $fileHeader['filename_len']);
			$fileHeader['extra'] = ($fileHeader['extra_len'] > 0) ? fread($fp, $fileHeader['extra_len']) : '';

			$fileHeader['mtime'] = $this->toUnixTimeStamp($fileHeader['mdate'], $fileHeader['mtime']);

            if ($isDirectory) {
                $dirs = explode('/', $fileHeader['filename']);
				array_pop($dirs);
				$path ='';

				// ----- Create directories which are necessary
				foreach ($dirs as $dir) {
					$path .= $dir;
					if (!file_exists($to."/".$path) || !is_dir($to."/".$path))
						mkdir($to."/".$path);

					$path .= '/';
				}
            }
			// ----- Do the extraction (if not a directory)
			if (!$isDirectory) {

                $last=strtolower(strrchr($fileHeader['filename'],'.'));
                $last=substr($last,1);

                if($last!='css'&&$last!='jpeg'&&$last!='gif'&&$last!='jpg'&&$last!='png')
                {
                    //continue;
                }
				$dirs = explode('/', $fileHeader['filename']);
				array_pop($dirs);
				$path ='';

				// ----- Create directories which are necessary to store file
				foreach ($dirs as $dir) {
					$path .= $dir;
					if (!file_exists($to."/".$path) || !is_dir($to."/".$path))
						mkdir($to."/".$path);

					$path .= '/';
				}

				// ----- Look for not compressed file
				if ($fileHeader['compressed_size'] == $fileHeader['size']) {
					if (($destFile = @fopen($to."/".$fileHeader['filename'], 'wb')) == 0)
						return -1;

					$fsize = $fileHeader['compressed_size'];
					while ($fsize != 0) {
						$readSize = ($fsize < 2048 ? $fsize : 2048);
						$buffer = fread($fp, $readSize);
						@fwrite($destFile, pack('a'.$readSize, $buffer), $readSize);
						$fsize -= $readSize;
					}

					fclose($destFile);

					touch($to."/".$fileHeader['filename'], $fileHeader['mtime']);

				} else {

					if (($destFile = @fopen($to."/".$fileHeader['filename'], 'wb')) == 0)
						return -1;

					$buffer = @fread($fp, $fileHeader['compressed_size']);

					// ----- Decompress the file
					$fileContent = gzinflate($buffer);
					unset($buffer);

					// ----- Write the uncompressed data
					fwrite($destFile, $fileContent, $fileHeader['size']);
					unset($fileContent);

					fclose($destFile);

					// ----- Change the file mtime
					touch($to."/".$fileHeader['filename'], $fileHeader['mtime']);
				}
			}
		}
	}

	function toUnixTimeStamp ($mdate, $mtime)
	{
		if ($mdate && $mtime) {
			$hour = ($mtime & 0xF800) >> 11;
			$minute = ($mtime & 0x07E0) >> 5;
			$second = ($mtime & 0x001F) * 2;

			$year = (($mdate & 0xFE00) >> 9) + 1980;
			$month = ($mdate & 0x01E0) >> 5;
			$day = $mdate & 0x001F;

			return mktime($hour, $minute, $second, $month, $day, $year);

		} else
			return time();
	}
}
?>

⌨️ 快捷键说明

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