MySQLi. Upload and save image file as BLOB. PostFile. PostText

Another idea would be to have the images in the file system, a php code to compress them in .zip and download the .zip to the app. Using an extension unzip the .zip.

Resize the images before uploading as blobs. Depends on what the images are for. If thumbnails will do, then image/blob size will be less.

JQuery can limit the returned data for scrolled output.

ZIP the images folder at the host side is very interesting. Could this be done ?

Open a new topic about zip - php

Hi @Juan_Antonio ,

I've read this post and since it is still opened, I am posting here. But if it is necessary, I can open another post.

I have used your extension which was indicated by TIMAI2, and I am having a problem when I am trying to save the image in the BLOB field, in MySQL remote server. What I am doing to send the image to the server is this:

1 - I am taking the photo and saving the Base64 string in a text field on a local SQLite, like this:

image

2 - In other screen of my app, I send to the remote server:

In my PHP script, I am doing this:

$_foto = $_POST['foto'];

// Mudando alguns caracteres da foto enviada pelo aplicativo
$_foto_gravar = strtr($_foto, '-_,', '+/=');
$_foto_gravar = base64_decode($_foto_gravar);

// Salvando em arquivo pra poder gravar
//$caminho = '../tmp/'; //voltar uma pasta
$_arquivo = $caminho.session_id().mt_rand(1000000000, 1999999999).'.jpg';
file_put_contents($_arquivo,$_foto_gravar); //salvamos em DISCO
$fp = fopen($_arquivo, 'r'); //abrimos o arquivo/imagem para montar a instrução SQL
$dados_foto = fread($fp, filesize($_arquivo));
$dados_foto = addslashes($dados_foto); //importante isso
fclose($fp); //fechar arquivo/imagem

And after the UPDATE command, it stores in the MySQL BLOB field. The only problem I am facing is that the image saved in MySQL is only a black image. So, what am I doing wrong?

TIA,

I would start here:

See how Juan uses str_replace:

2 Likes

hmmm yes, @TIMAI2 . It's a good start. let's see then.

And that was the trick!!! worked perfectly!!! It's funny that this PHP script was working before, but... the important thing that it is solved!!

Thank you!!!

1 Like