Small file PHP + SQLite Storage Solution

Source: Internet
Author: User

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 nowCode:
Create a database file: php1.phpCopy codeThe Code is as follows: $ db = new sqlite3 ('mysqlitedb. db ');

// Obtain the binary stream of a file
$ 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 ('201742119720101001x ', 'zhangsan ',?) ");
$ Stmt-> bindvalue (1, $ contents, sqlite3_blob );
$ Stmt-> execute ();

Read data files: php2.phpCopy codeThe Code is as follows: <? 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 ();
}
?>

Web page reference:Copy codeThe Code is as follows: <! 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 tutorial </title>
</Head>
<Body>

</Body>
</Html>

Related Article

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.