Encode an image and pass it to a database

Yes it can, with correct setup at the server, the correct php file, and the correct blocks in AI2

Now I've caused my phone to lock up using this !

Again, you do not show, in their entirety, your relevant blocks....

Before, we uploaded a cat. Now, we are going to upload a dog.

borrar_sube3.aia (166.8 KB)

<?php
 // 1.- IDENTIFICACION nombre de la base, del usuario, clave y servidor
$db_host="localhost";
$db_name="id1975555_base"; // fake
$db_login="id1975555_juan"; // fake
$db_pswd="Contraseña"; // fake

// 2.- CONEXION A LA BASE DE DATOS
$link = new mysqli($db_host, $db_login, $db_pswd, $db_name);

// 3.- OBTENER ARCHIVO - GET FILE
  $file = file_get_contents('php://input');
   if (file_put_contents($_GET['archivo'],$file == TRUE))  {
   
		$nombre = $_GET['archivo'];
		$extension = pathinfo($nombre, PATHINFO_EXTENSION);
		// $extension = mime_content_type($nombre);
		
		// Archivo a MySQLi. BLOB. - File to MysQLi BLOB.
		$blob = mysqli_real_escape_string($link, $file);
		$resultado = mysqli_query($link, "INSERT INTO dibujos (imagen, extension, nombre) VALUES ('$blob', '$extension', '$nombre')");
		mysqli_close($link);	
		echo $nombre." uploaded.";
   } else {
	echo "Error";  
   }
?>

Here it is!

1 Like

Can you adjust this to store an image just taken with the camera ?

Does my example work for you? can you upload the perro.png file to your database?

I'm sure it works. It's not finding the directory. A small issue. Can you please change the above blocks to allow picking an image from your phone.

You can get the file path with this code:

trtrt445454

borrar_sube4.aia (2.6 KB)


What am I doing wrong !

You do not need to make a fullPath, just use the path in Etiqueta3.Text.

Use Do It when using companion to see the values that are being generated. You learn a lot about how to debug your own work....

This runtime error directory is not matching anything I send. I've tried them all !

You did not follow the blocks supplied by @Juan_Antonio ....

files/assets

Why is it looking in this directory when I an sending the files/pictures directory

Did you use Do It to see what each variable/action is being returned? from that you can work out the correct file path you need to set.

Can a host block transferring BLOB data. I have copied these BLOCKS and code exactly and the name arrives in the database but not the BLOB.

In the example borrar_sube3.aia you answered: "I'm sure it works. It's not finding the directory." does that mean that it worked for you or that it didn't work for you?

Juan, I downloaded your code. I uploaded a trial image to the media folder. I copied your PHP exactly. I ran the APP. The image name and extension loaded to the database and the file manager. The BLOB did not. This must be a hosting issue and I opened a ticket with them.

Create and upload to your server a file called info.php with this content:

<?php
phpinfo();
?>

Open it...

https://domain.abc/.../info.php

Check if file_uploads is on

if I hard code an image into the URL domain.com/loadim.php?image=pic.jpg it works fine.