Small file php+sqlite storage scheme _php Tips

Source: Internet
Author: User
Tags sqlite stmt
We grassroots owners buy the virtual host often have a file limit, a large number of small files occupy a large number of resources, the outdated essence area also has a brother recommended watercress solution, but to have host permissions. Can only install ideas, using Php+sqlite to solve the problem, after my test, practical, now recommended to everyone.

Now expose the code:
To create a database file: php1.php
Copy Code code as follows:

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

Get file 2 feed stream
$filename = "Yun_qi_img/logo.gif";
$handle = fopen ($filename, "R");
$contents = Fread ($handle, FileSize ($filename));
Fclose ($handle);
Creating data Tables
$db->exec (' CREATE TABLE person (idnum text,name text,photo BLOB) ');

$stmt = $db->prepare ("INSERT into person VALUES (' 41042119720101001X ', ' John ',?)");
$stmt->bindvalue (1, $contents, Sqlite3_blob);
$stmt->execute ();

Read Data file: php2.php
Copy Code code 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 Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv=" Content-type " Content= "text/html; Charset=utf-8 "/>
<title>ansys Tutorials </title>
<body>

</body>
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.