本文实例讲述了php中adodbzip类程序代码。分享给大家供大家参考。具体如下:
复制代码 代码如下:<"GET " . $url_arr ['path'] . " HTTP/1.0rnHost: " . $url_arr ['host'] . " rnConnection: closernrn";
fputs ( $fp, $out );
if (feof ( $fp )) {
break;
}
$buffer = fgets ( $fp, 1024 );
if (! preg_match ( '/^HTTP/1.d 200 /i', $buffer )) {
break;
}
$content_length = false;
$content_start = false;
while ( ! feof ( $fp ) ) {
$buffer = fgets ( $fp, 1024 );
if ($buffer === "rn") {
$content_start = true;
break;
}
if (preg_match ( '/^Content-Length:s*(d+)/i', $buffer, $matches )) {
$content_length = ( int ) $matches [1];
}
}
if ($content_length === false || $content_start === false) {
break;
}
$content = stream_get_contents ( $fp );
if ($content === false) {
break;
}
$result = file_put_contents ( self::$zip_file, $content );
unset ( $content );
if ($result === false) {
break;
}
fclose ( $fp );
} while ( $break = false );
if ($break) {
header ( 'Content-type: text/html;charset=utf-8' );
die ( '请下载文件 <a href="' . self::$zip_url . '">' . self::$zip_url . '.zip</a > 保存为 ' . self::$zip_file );
}
}
}
// 创建目录
$tmp_dir = dirname ( $tmp_file );
if (! is_dir ( $tmp_dir )) {
if (mkdir ( $tmp_dir, 0777, true ) === false) {
header ( 'Content-type: text/html;charset=utf-8' );
die ( '请创建目录 ' . $tmp_dir );
}
}
// 打开压缩文件
$zip = zip_open ( $zip_file );
if (! is_resource ( $zip )) {
return false;
}
// 寻找解压文件
do {
$entry = zip_read ( $zip );
if (! is_resource ( $entry )) {
return false;
}
if (zip_entry_name ( $entry ) == $entry_file) {
break;
}
} while ( true );
// 转存压缩文件
zip_entry_open ( $zip, $entry );
file_put_contents ( $tmp_file, zip_entry_read ( $entry, zip_entry_filesize ( $entry ) ) );
zip_entry_close ( $entry );
zip_close ( $zip );
}
// 打开文件
$this->handle = fopen ( $tmp_file, $mode );
if (! is_resource ( $this->handle )) {
return false;
}
return true;
}
/**
* stream_read
* @param int $count
* @return string
*/
public function stream_read($count) {
return fread ( $this->handle, $count );
}
/**
* stream_seek
* @param int $offset
* @param int $whence=SEEK_SET
* @return bool
*/
public function stream_seek($offset, $whence = SEEK_SET) {
return fseek ( $this->handle, $offset, $whence );
}
/**
* stream_set_option
* @param int $option
* @param int $arg1
* @param int $arg2
* @return bool
*/
public function stream_set_option($option, $arg1, $arg2) {
return false;
}
/**
* stream_stat
* @return array
*/
public function stream_stat() {
return fstat ( $this->handle );
}
/**
* stream_tell
* @return int
*/
public function stream_tell() {
return ftell ( $this->handle );
}
/**
* stream_write
* @param string $data
* @return int
*/
public function stream_write($data) {
return fwrite ( $this->handle, $data );
}
/**
* url_stat
* @param string $path
* @param int $flag
* @return array
*/
public function url_stat($path, $flag) {
if (! preg_match ( '/^.*"codetitle">复制代码 代码如下:<?php
include_once 'AdodbZip.php';
$db = AdodbZip::init(NewADOConnection('mysqlt'));
echo $db->GetOne('SELECT NOW()');
?>
也是两步.
1. 包含AdodbZip.php文件
2. AdodbZip::init(...)函数对adodb连接类进行初始化
希望本文所述对大家的PHP程序设计有所帮助。