我們草根站長購買的虛擬主機往往都有文件數量限制,大量小文件占用大量資源,落伍精華區也有兄弟推薦豆瓣的解決方法,但是要有主機權限。只能另裝思路,采用php+SQLite解決問題,經過我測試,切實可行,現在推薦給大家。
現在公開代碼:
創建數據庫文件:php1.php
復制代碼 代碼如下:
$db = new SQLite3('mysqlitedb.db');
//獲取文件2進制流
$filename = "http://www.jb51.net/logo.gif";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize ($filename));
fclose($handle);
//創建數據表
$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();
讀數據文件:php2.php
復制代碼 代碼如下:
<?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();
}
?>
網頁引用:
復制代碼 代碼如下:
<!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.jb51.net/info.php" width="22" height="30" />
</body>
</html>