Small file php+SQLite storage solution_PHP tutorial

WBOY
Release: 2016-07-21 15:34:31
Original
934 people have browsed it

The virtual host purchased by our grassroots webmasters often has a limit on the number of files, and a large number of small files occupy a lot of resources. Some brothers in the outdated essence area also recommended Douban's solution, but they must have host permissions. I can only install another idea and use php+SQLite to solve the problem. After I tested it, it is feasible and I recommend it to everyone now.

Now make the code public:
Create database file: php1.php

Copy the code The code is as follows:

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

//Get the file binary stream
$filename = "http://www.jb51.net/logo.gif" ;
$handle = fopen($filename, "r");
$contents = fread($handle, filesize ($filename));
fclose($handle);
//Create Data table
$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();

Read data file: php2.php
Copy code The code is as follows:

$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 Tutorial



http://www.bkjia.com/PHPjc/322429.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/322429.html

TechArticle
The virtual hosts purchased by our grassroots webmasters often have restrictions on the number of files. A large number of small files occupy a lot of resources and are outdated. Some brothers in the district also recommended Douban’s solution, but it requires a host...

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template