jquery文件上传到base64数据库
问题描述:
我遇到麻烦使用Jquery文件上传引导皮肤(https://github.com/blueimp/jQuery-File-Upload)。该程序本身工作得很好,即使在github(https://github.com/blueimp/jQuery-File-Upload/wiki/Working-with-databases)上描述的数据库也是功能性的。jquery文件上传到base64数据库
但我真正需要的是将图片以base64格式保存在数据库中。我似乎无法得到它。所以在add_img函数中,我需要以某种方式获取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;
}
答
使用以下代码将图像转换为base64并将其存储到数据库。
$imagedata = file_get_contents("filepath/filename.jpg");
$base64data = base64_encode($imagedata);
编辑:
$file->size = $file_size;//from current code
$imagedata = file_get_contents($file_path);
$base64data = base64_encode($imagedata);
$this->add_img($base64data);
希望这会为你工作
这部分我确实媒体链接发现。我只是不知道这些数据在文件中的可用位置。因为在某些时候它必须制作实际的图片(imagedata),但我看不到在哪里。 – Matt 2013-04-06 17:11:50
$ imagedata = file_get_contents($ file_path); – 2013-04-06 17:57:12
我看到你在那里做了什么。它的工作原理,谢谢! – Matt 2013-04-06 19:13:13