Upload to FTP through PHP

0

Good morning. I am trying to upload a file through an HTML form with PHP. The connection is successful and moves successfully to the route, but at the time of making the upload fails, giving me in Filezilla Server the failure "550 Permission denied" I have verified the permissions of the folder where it is uploaded but the permissions are set correctly. I enclose the code fragments in charge of this process:

HTML form:

 <form id="subida" action="php/upload-ftp.php" method="post" enctype="multipart/form-data"> 
<div>  
  <label class="btn btn-primary">
    Seleccionar archivo&hellip; <input name="upload" type="file" id="file" style="display: none;">
  </label>
    <button type="submit" name="submit" id="btnUpload" class="btn btn-info" value="Enviar"> <span class="glyphicon glyphicon-upload" aria-hidden="true"></span></button>
  </div>

</form>

This form is processed with an AJAX call:

ev.preventDefault();
    var formd = new FormData(ev.currentTarget);
    $.ajax({
            url: ev.currentTarget.getAttribute('action'),
            type: "POST",
            data: formd,
            processData: false,
            contentType: false,
            success: function(r){
                $("<div class='alert alert-success' id='msnSubDoc' role='alert'>Documento subido con éxito</div>").insertBefore("#subida");
            }

    }); 

And this connects with the PHP file that processes the upload:

<?php    

$ destination="/".$_ COOKIE ['route']." / uploads / ";

# Definimos las variables

$host="url servidor";

$port="puerto";

$user="usuario";

$password="contraseña";

$ruta=$destino;



# Realizamos la conexion con el servidor

$conn_id=@ftp_connect($host,$port);

if($conn_id)

{   



    # Realizamos el login con nuestro usuario y contraseña

    if(@ftp_login($conn_id,$user,$password))

    {


        echo "Conexion establecida";
        # Canviamos al directorio especificado

        if(@ftp_chdir($conn_id,$ruta))

        {
            # Subimos el fichero
            echo "Ruta encontrada";
            ftp_pasv($conn_id, true);   
            if(@ftp_put($conn_id,$ruta,$_FILES['upload']['tmp_name'],FTP_BINARY)){

                    echo "Fichero subido correctamente";
            }else{


                echo "No ha sido posible subir el fichero";

            }
        }else{
            echo "No existe el directorio especificado";
        }               
    }else{
        echo "El usuario o la contraseña son incorrectos";
        # Cerramos la conexion ftp
        ftp_close($conn_id);
    }
}else{
    echo "No ha sido posible conectar con el servidor";
}

? >

I appreciate the help in advance.

    
asked by AntonioMP87 21.09.2017 в 12:26
source

0 answers