Our grassroots webmaster purchase of the virtual host often have a limited number of files, a large number of small files occupy a large number of resources, the outdated essence of the brother recommended watercress solution, but to have host permissions. Can only be installed ideas, the use of php+sqlite to solve problems, after I test, practical, now recommended to everyone.
Now expose the code:
Create database file: php1.php
Copy the Code code as follows:
$db = new SQLite3 (' mysqlitedb.db ');
Get file 2 binary stream
$filename = "Http://www.jb51.net/logo.gif";
$handle = fopen ($filename, "R");
$contents = Fread ($handle, FileSize ($filename));
Fclose ($handle);
Create a data table
$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
Copy the Code code 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 ();
}
?>
Web page reference:
Copy the Code code as follows:
Ansys Tutorials
The above describes the small file Php+sqlite storage scheme, including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.