小檔案php+SQLite儲存方案_PHP教程

來源:互聯網
上載者:User
我們草根站長購買的虛擬機器主機往往都有檔案數量限制,大量小檔案佔用大量資源,落伍精華區也有兄弟推薦豆瓣的解決方案,但是要有主機許可權。只能另裝思路,採用php+SQLite解決問題,經過我測試,切實可行,現在推薦給大家。

現在公開代碼:
建立資料庫檔案:php1.php
複製代碼 代碼如下:
$db = new SQLite3('mysqlitedb.db');

//擷取檔案2進位流
$filename = "http://www.jb51.net/logo.gif";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize ($filename));
fclose($handle);
//建立資料表
$db->exec('CREATE TABLE person (idnum TEXT,name TEXT,photo BLOB)');

$stmt = $db->prepare("INSERT INTO person VALUES ('41042119720101001X', '張三',?)");
$stmt->bindValue(1, $contents, SQLITE3_BLOB);
$stmt->execute();

讀資料檔案:php2.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();
}
?>

網頁引用:
複製代碼 代碼如下:




ANSYS教程





http://www.bkjia.com/PHPjc/322429.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/322429.htmlTechArticle我們草根站長購買的虛擬機器主機往往都有檔案數量限制,大量小檔案佔用大量資源,落伍精華區也有兄弟推薦豆瓣的解決方案,但是要有主機...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.