当前位置: 移动技术网 > IT编程>开发语言>PHP > 小文件php+SQLite存储方案

小文件php+SQLite存储方案

2019年04月27日  | 移动技术网IT编程  | 我要评论

可乐福,女子被鬼故事吓坏,吴爰英与卢恩光

我们草根站长购买的虚拟主机往往都有文件数量限制,大量小文件占用大量资源,落伍精华区也有兄弟推荐豆瓣的解决方法,但是要有主机权限。只能另装思路,采用php+sqlite解决问题,经过我测试,切实可行,现在推荐给大家。

现在公开代码:
创建数据库文件:php1.php
复制代码 代码如下:

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

//获取文件2进制流
$filename = "//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="//www.jb51.net/info.php" width="22" height="30" />
</body>
</html>

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网