Image storage - php mysql stores base64 images
ringa_lee
ringa_lee 2017-05-19 10:07:42
0
4
935

In the HTML5 canvas, I used a third-party control for making emoticon packages, and now I want to upload the completed emoticon package to the mysql database. Whether you upload it to a local server and then store the file address in the database, or use it in blob form, you can do it. Please tell me how to do it. I use canvas.todataurl to convert the image into base64 encoding, then use ajax to send the encoding to the stored page, and use $_POST["image"] to obtain the base64 encoding. I don't want to directly input the base64 encoding into the database because it is too big, but I don't know how to use PHP to convert the BASE64 encoding of the image into a BLOB. Can I convert the encoding into an image and then upload the image directly to the database? But I remember that file_get_content seems to be only available locally and not on the server. The following is the base64 encoding code I currently use to get the image

$data = $_POST["image"];
$data = str_replace('data:image/png;base64,', '', $data);
$data = str_replace(' ' ,' ',$data);

$data = base64_decode($data);

No matter what method is used, as long as the base64-encoded image can be entered into the database

ringa_lee
ringa_lee

ringa_lee

reply all(4)
我想大声告诉你

Files are generally stored in addresses. If they are decoded and saved as files, wouldn’t the data inventory file path work?

習慣沉默

Generally, it is generated locally first and the address is stored directly.

过去多啦不再A梦

file_get_contents() can be used, I always use this

小葫芦

Generally speaking, you will upload the file to Qiniu, get a network path, and save the path to the database

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!