Upload an image to hostinger with web services

0

I have an account with hostinger and I want to upload an image through a web services with php I see that the image goes to the database but it is not recorded in the root folder of the hosting. I attach my php code which is very simple

   <?php

$cnx=new  PDO("mysql:host=mysql.hvbnvr.com;dbname=u1fhghfh","u17gfhfggft","I0@hfghfghfghfghFy");

$nombre=$_POST["nombre"];
    $imagen=$_POST["imagen"];

    $server_ip = gethostbyname(gethostname());
    $path="dacepsacgde.com/solicitudfalta/$nombre.jpg";

        file_put_contents("$path", base64_decode($imagen));

        $bytesArchivo=file_get_contents($path);

    $res=$cnx->query("insert into solicitudfaltas values(null,'file_get_contents($imagen)')");


        if($res > 0){
            echo "success";
        }else{
            echo "failed";
        }

?>

The problem is that if you save in the database but not in the server. I already give all the permissions that hostinger gives me if someone can help me with this topic I would appreciate it a lot.

    
asked by Jinex Velarde 09.10.2017 в 06:45
source

1 answer

1

To obtain a file we use $_FILE no $_POST . You should also remove the quotes in file_put_contents ("$ path", ...) since $ path is a variable.

Here is the complete code:

<?php

    $cnx=new  PDO("mysql:host=mysql.hvbnvr.com;dbname=u1fhghfh","u17gfhfggft","I0@hfghfghfghfghFy");

    $nombre=$_POST["nombre"];
    $imagen=$_FILE["imagen"];

    $server_ip = gethostbyname(gethostname());
    $path= "dacepsacgde.com/solicitudfalta/$nombre.jpg";

    file_put_contents($path, base64_decode($imagen));

    $bytesArchivo = file_get_contents($path);
    $res=$cnx->query("insert into solicitudfaltas values(null,'file_get_contents($imagen)')");


    if($res > 0){
        echo "success";
    }else{
        echo "failed";
    }

?>
    
answered by 09.10.2017 в 15:33