Heim  >  Artikel  >  Backend-Entwicklung  >  小文件php+SQLite存储方案_PHP教程

小文件php+SQLite存储方案_PHP教程

WBOY
WBOYOriginal
2016-07-21 15:34:31894Durchsuche

我们草根站长购买的虚拟主机往往都有文件数量限制,大量小文件占用大量资源,落伍精华区也有兄弟推荐豆瓣的解决方法,但是要有主机权限。只能另装思路,采用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
复制代码 代码如下:

$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();
}
?>

网页引用:
复制代码 代码如下:





ANSYS教程


小文件php+SQLite存储方案_PHP教程


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/322429.htmlTechArticle我们草根站长购买的虚拟主机往往都有文件数量限制,大量小文件占用大量资源,落伍精华区也有兄弟推荐豆瓣的解决方法,但是要有主机...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn