Small file PHP +SQLite storage scheme
- 2020-03-31 21:04:45
- OfStack
We grassroots webmaster purchase of virtual host often have the number of documents limit, a large number of small files occupy a large number of resources, behind the essence area also has brother recommended douban solution, but to have host rights. Can only be installed in another way, using PHP +SQLite to solve the problem, after my test, practical, now recommend to you.
Now expose the code:
Create database file: php1.php
Read data file: php2.php
Page reference:
Now expose the code:
Create database file: php1.php
$db = new SQLite3('mysqlitedb.db');
//Gets the file 2 base stream
$filename = "//www.jb51.net/logo.gif";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize ($filename));
fclose($handle);
//Create data tables
$db->exec('CREATE TABLE person (idnum TEXT,name TEXT,photo BLOB)');
$stmt = $db->prepare("INSERT INTO person VALUES ('41042119720101001X', ' Zhang SAN ',?)");
$stmt->bindValue(1, $contents, SQLITE3_BLOB);
$stmt->execute();
Read data file: 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();
}
?>
Page reference:
<!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 The tutorial </title>
</head>
<body>
<img src="//www.jb51.net/info.php" width="22" height="30" />
</body>
</html>