Small File Php+sqlite storage scheme

Source: Internet
Author: User
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.