Upload file to server hosting by PHP. Encode file to Base 64 extension

Hello friends,

there are several ways to upload a file to our server: FTP, Postfile,… in this example we are going to convert the file into text using a Base 64 extension and upload that text using PHP.

You can download the extension com.KIO4_Base64.aix of:
http://kio4.com/appinventor/277_extension_imagen_string.htm

In this example I will use 000webhost server

phpsubir

<?php
// Juan A. Villalpando
// kio4.com
// https://kio4.000webhostapp.com/dibujo.jpg

$datos=$_POST;
$contenido=$datos['contenido'];

$plainText = base64_decode(str_replace(array('-', '_',' ','\n'), array('+', '/','+',' '), $contenido));
$ifp = fopen( "dibujo.jpg", "wb" );
fwrite( $ifp,  $plainText );
fclose( $ifp );

echo "Creo que ha subido";
?>

Podremos ver la imagen:
https://kio4.000webhostapp.com/dibujo.jpg

p327C_subir_archivo_texto.aia (324.4 KB)

Regards,
Juan A. Villalpando.

1 Like

With this code you can set the name of the file.

phpsubir2

<?php
// Juan A. Villalpando
// kio4.com
// https://kio4.000webhostapp.com/name_file.abc

$datos=$_POST;
$contenido=$datos['contenido'];
$nombre=$datos['nombre'];

$plainText = base64_decode(str_replace(array('-', '_',' ','\n'), array('+', '/','+',' '), $contenido));
$ifp = fopen( $nombre, "wb" );
fwrite( $ifp,  $plainText );
fclose( $ifp );

echo "Creo que ha subido";
?>

Another example:

The Camera takes picture and upload to the server.

thanks both! taifun for redirect me to good tutorial and Juan Antonio you opened my eyes on split list item list :slight_smile:
i solved in this way:


blocks (5)