Image upload to Hostinger directory

2

I'm trying to upload an image to a Hostinger directory, but I'm not able to do so.

Below is a PHP script.

Note: The Base64 image is coming from an Android app.

<?php

$ftp_server = "ftp.endereço.server";
$ftp_user = "*****";
$ftp_pass = "*****";
$imageCodificada = $_POST['imageCodificada'];


//DECODIFICAR IMAGEM
$imageDecodificada = base64_decode($imageCodificada);


// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Não foi possível estabelecer conexão com $ftp_server"); 

// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
    echo "Conectado! na $ftp_user@$ftp_server\n";
    file_put_contents(include($_SERVER['DOCUMENT_ROOT']."/public_html/imagens/fotos_func/TESTE.jpg"), imageDecodificada);



} else {
    echo "Não foi possível estabelecer conexão com $ftp_user\n";
}

// close the connection
ftp_close($conn_id);  
?>

My PHP script does not give error, however the file does not appear in the directory.

Someone could help me on how to do this.

Thank you.

    
asked by anonymous 09.08.2016 / 23:11

1 answer

1

That "include" does not seem to make sense:

file_put_contents(include($_SERVER['DOCUMENT_ROOT']."/public_html/imagens/fotos_func/TESTE.jpg"), imageDecodificada);

Remove it:

file_put_contents($_SERVER['DOCUMENT_ROOT']."/public_html/imagens/fotos_func/TESTE.jpg", imageDecodificada);

You still need to upload via FTP. Because the physical file was created locally. Now you must send it. But in your code there is no send command. You are just opening and closing FTP without doing anything.

    
10.08.2016 / 00:57