Jquery File upload to database in base64

≡放荡痞女 提交于 2020-01-16 01:06:18

问题


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:


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



来源:https://stackoverflow.com/questions/15852496/jquery-file-upload-to-database-in-base64

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!