Small file php + SQLite storage solution

Source: Internet
Author: User
In the context of the rapid development of the Internet, the data content on the network grows exponentially, among them, the fastest growing and most likely to challenge the information infrastructure is a large number of small files (tablets, e-books, emails, etc ). The number of files on the virtual hosts purchased by our grassroots webmaster is usually limited. a large number of small files occupy a large amount of resources. in the outdated vertices, Douban is recommended for solutions, but the host permission is required. I can only install another idea and use php + SQLite to solve the problem. after my tests, it is practical and recommended to you now.

Public Code now:
Create a database file: php1.php
The code is as follows:
$ Db = new SQLite3 ('mysqlitedb. db ');

// Obtain the binary stream of a file
$ Filename = "http://www.bitsCN.com/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 ('201742119720101001x ', 'zhangsan ',?) ");
$ Stmt-> bindValue (1, $ contents, SQLITE3_BLOB );
$ Stmt-> execute ();

Read Data Files: php2.php
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 ();
}
?>

Web page reference:
The code is as follows:




ANSYS tutorial




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.