欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

小文件php+SQLite存儲(chǔ)方案

 更新時(shí)間:2010年09月04日 00:14:59   作者:  
在互聯(lián)網(wǎng)快速發(fā)展的背景下,網(wǎng)絡(luò)上的數(shù)據(jù)內(nèi)容呈幾何級(jí)的增長,而其中增長最快并且最容易給信息基礎(chǔ)架構(gòu)帶來挑戰(zhàn)的就是數(shù)目龐大的小文件(如圖片、電子圖書、郵件等)。
我們草根站長購買的虛擬主機(jī)往往都有文件數(shù)量限制,大量小文件占用大量資源,落伍精華區(qū)也有兄弟推薦豆瓣的解決方法,但是要有主機(jī)權(quán)限。只能另裝思路,采用php+SQLite解決問題,經(jīng)過我測(cè)試,切實(shí)可行,現(xiàn)在推薦給大家。

現(xiàn)在公開代碼:
創(chuàng)建數(shù)據(jù)庫文件:php1.php
復(fù)制代碼 代碼如下:

$db = new SQLite3('mysqlitedb.db');

//獲取文件2進(jìn)制流
$filename = "http://www.dbjr.com.cn/logo.gif";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize ($filename));
fclose($handle);
//創(chuàng)建數(shù)據(jù)表
$db->exec('CREATE TABLE person (idnum TEXT,name TEXT,photo BLOB)');

$stmt = $db->prepare("INSERT INTO person VALUES ('41042119720101001X', '張三',?)");
$stmt->bindValue(1, $contents, SQLITE3_BLOB);
$stmt->execute();

讀數(shù)據(jù)文件:php2.php
復(fù)制代碼 代碼如下:

<?php
$pdo = new SQLite3('mysqlitedb.db');
$results = $pdo->query('select * from person');
while ($row = $results->fetchArray()) {
ob_start();
header("Content-Type: image/jpg");
echo $row['photo'] ;
ob_end_flush();
}
?>

網(wǎng)頁引用:
復(fù)制代碼 代碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ANSYS教程</title>
</head>
<body>
<img src="http://www.dbjr.com.cn/info.php" width="22" height="30" />
</body>
</html>

相關(guān)文章

最新評(píng)論