Home  >  Q&A  >  body text

Image storage - php mysql stores base64 images

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_leeringa_lee2682 days ago907

reply all(4)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-05-19 10:09:42

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

    reply
    0
  • 習慣沉默

    習慣沉默2017-05-19 10:09:42

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

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-19 10:09:42

    file_get_contents() can be used, I always use this

    reply
    0
  • 高洛峰

    高洛峰2017-05-19 10:09:42

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

    reply
    0
  • Cancelreply