我们草根站长购买的虚拟主机往往都有文件数量限制,大量小文件占用大量资源,落伍精华区也有兄弟推荐豆瓣的解决方法,但是要有主机权限。只能另装思路,采用php+SQLite解决问题,经过我测试,切实可行,现在推荐给大家。
现在公开代码:
创建数据库文件:php1.php
<BR>$db = new SQLite3('mysqlitedb.db'); <br><br>//获取文件2进制流 <BR>$filename = "http://www.gaodaima.com/logo.gif"; <BR>$handle = fopen($filename, "r"); <BR>$contents = fread($handle, filesize ($filename)); <BR>fclose($handle); <BR>//创建数据表 <BR>$db->exec('CREATE TABLE person (idnum TEXT,name TEXT,photo BLOB)'); <br><br>$stmt = $db->prepare("INSERT INTO person VALUES ('41042119720101001X', '张三',?)"); <BR>$stmt->bindValue(1, $contents, SQLITE3_BLOB); <BR>$stmt->execute(); <BR>
读数据文件:php2.php
<BR><?php <BR>$pdo = new SQLite3('mysqlitedb.db'); <BR>$results = $pdo->query('select * from person'); <BR>while ($row = $results->fetchArray()) { <BR>ob_start(); <BR>header("Content-Type: image/jpg"); <BR>echo $row['photo'] ; <BR>ob_end_flush<strong>(本文来源gaodai#ma#com搞@@代~&码网</strong><pre>搞代gaodaima码
();
}
?>
网页引用:
<BR> <BR> <BR> <BR><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <BR><title>ANSYS教程</title> <BR> <BR><body> <BR> <BR> <BR> <BR>