關於 PHP, Linux, Open Source 及個人生活記載的網誌。
RSS icon
  • 使用 MySQL 儲存圖片

    Posted on December 10th, 2007 Sam Tang 1 comment

    其實這個方法不單可以用在 MySQL,在其他資料庫及非圖片也應該也沒問題,原理是 使用 base64_encode() 將檔案轉成 MIME base64 字串編碼,然後放入資料表,當然儲存檔案用的欄位要夠大才可以,在取出時用 base64_decode() 回復原狀即可,以下是例子:

    PHP:
    1. <?php
    2. $file_str=base64_encode($file);
    3. mysql_query("insert into table_name values ('$file_str')");
    4. ?>


     

    One response to “使用 MySQL 儲存圖片”

    1. mysql 不是有 BLOG 麼…

    Leave a reply

    *
    To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
    Click to hear an audio file of the anti-spam word