Hello. I installed a graphic editor on my site, and when I insert an image and save it, all data is encoded in base64 and sent to the database. The problem is to display images later. Text displays, but not all the images. I noticed that it does not display only large images. What could be the problem?

Here is the output code:

strip_tags(html_entity_decode($text, ENT_QUOTES, 'UTF-8'), '<img><a><b><i><u><ul><li><ol><span><div><br><p>') 

The $text variable contains text and images.

Perhaps it is worth some kind of data limit that is transmitted? I deduce the whole thing with Ajax.

  • Can a field in the database where you store a string for example varchar (250) and is it truncated? ) Or is the text variable exactly all the information? - Moonvvell
  • @Moonvvell, in the database type of the field is not varchar but text, everything in the variable is exactly there, through the database I see what's there. - Abmin
  • @Moonvvell, can it be that it's about hosting? I found something about ModSecurity - Abmin
  • And if you print $ text as text, it completely ends in = or ==? - Talleyran
  • one
    Try LONGTEXT instead of TEXT . Or better still store pictures in files! - Crantisz

3 answers 3

The data must be transmitted in a form-data format. And stored on a server not in the database.

  • Thank. And he did. Now I use the Imgur service (as on this site). But since I have an ssl certificate and imgur doesn’t have it, then when I upload an image I get an exclamation mark instead of a green lock. - Abmin
  • And there is some kind of error. I understand correctly you are uploading a picture with an Ajax or have you inserted an iframe on the site? - Kostiantyn Okhotnyk
  • I did Ajax. Everything is already fine, I just regularly replace http with https - Abmin

Perhaps it is worth some kind of data limit that is transmitted?

Exactly. "base64 images" is nothing more than a data: URL . And the URL is limited in length and depends on the user agent and hop.

In addition, such encoding increases the amount of data. In binary form, the picture weighs much less. Therefore, there is simply no sense (and even harmful) to encode big data.

  • That is the best way to simply specify a link to the image in the database? - Abmin
  • Image in db? I do not know ... As for me - images need to be stored nat. faypam And paste the same. But maybe there are tasks where the database will be preferable, but I do not know such. - SeVlad

I noticed that it does not display only large images. What could be the problem?

In large images, it's more likely that strip_tags will ruin something. Probably, if you give such a picture in strip_tags , then the returned string will be different from the original one.

PS: http://ithappens.me/story/421

  • Without strip_tags , there are no images either, so I think the problem is still long. - Abmin