doumeitang572461 2013-04-06 15:07
浏览 77
已采纳

Jquery文件上传到base64中的数据库

I'm having trouble using the Jquery File uploader with bootstrap skin (https://github.com/blueimp/jQuery-File-Upload). The program itself works beautifully as is, even with the database which is functional too as described on github (https://github.com/blueimp/jQuery-File-Upload/wiki/Working-with-databases).

But what I really need is to save the picture in the database in base64 format. I can't seem to get it. So in the add_img function i need to somehow get the pic in base64.

// Standard file uploader code
function add_img($img_name)
{
    $add_to_db = $this->query("INSERT INTO pics (pic_name, pic) VALUES ('".$img_name."','picture in base64 here')");
    return $add_to_db;
}
  • 写回答

1条回答 默认 最新

  • dongyingtang3803 2013-04-06 15:26
    关注

    convert your image to base64 using following code and store it to db.

    $imagedata = file_get_contents("filepath/filename.jpg");
    $base64data = base64_encode($imagedata);
    

    EDIT:

    $file->size = $file_size;//from current code
    
    $imagedata = file_get_contents($file_path);
    $base64data = base64_encode($imagedata);
    $this->add_img($base64data);
    

    Hope this will work for you

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?