我們草根站長購買的虛擬機器主機往往都有檔案數量限制,大量小檔案佔用大量資源,落伍精華區也有兄弟推薦豆瓣的解決方案,但是要有主機許可權。只能另裝思路,採用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>