Error uploading to another server

2

I'm trying to write some images to another server pointing the IP and the folder, in my PHP code I pointed the path of the folder $_UP['pasta'] = '\\172.23.25.4\\manutencao\'; and the following error occurs:

  Warning: move_uploaded_file (\ 172.23.25.4 \ maintenance \ 1415978389.jpg): failed to open stream: Permission denied in / home / Systems / celu / public_html / souza / MANUTENCAO / projects / AD-ipco- Warning: move_uploaded_file (): Unable to move '/ tmp / phpEQFSvN' to '\ 172.23.25.4 \ maintenance \ 1415978389.jpg' ... online 126 Could not send the file , try again

Its pointing to the local folder path, it works fine, but if you point the folder path to another server this error occurs.

I granted folder and user permissions according to my search.

I created a new test file and now error occurs in function ftp_put () follows error

CONTAINED IN SERVER 172.23.25.4, WITH THE USER test Warning: ftp_put (): Could not create file. in /home/Internal_Systems/cel/public_html/jbarbin/upload/teste2/ftp_envia.php on line 28 FTP upload has failed!

follow the code

<form action="ftp_envia.php" enctype="multipart/form-data" method="post">
<input name="file" type="file" />
<input name="submit" type="submit" value="Upload File" />
</form>

Below the php code

<?php
ftp_server = "172.23.25.4";
$ftp_user_name = "teste";
$ftp_user_pass = "123456";
$destination_file = "/home/teste";
$source_file = $_FILES['file']['tmp_name'];

$conn_id = ftp_connect($ftp_server);

ftp_pasv($conn_id, true); 

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 

// check connection
if ((!$conn_id) || (!$login_result)) { 
    echo "FTP connection has failed!";
    echo "Attempted to connect to $ftp_server for user $ftp_user_name <br>"; 
    exit; 
} else {
    echo "CONETADO NO SERVIDOR $ftp_server, COM O USUARIO $ftp_user_name";
}

ftp_pasv($conn_id, true); 

// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file,  FTP_ASCII); 

// check upload status
if (!$upload) { 
    echo "<br>FTP upload has failed!";
} else {
    echo "Uploaded $source_file to $ftp_server as $destination_file";
}

// close the FTP stream 
ftp_close($conn_id);
?>
    
asked by anonymous 14.11.2014 / 16:33

3 answers

1

Solved the problem, I used the following code below: reference: link

if( $_SERVER['REQUEST_METHOD']=='POST' ){
//var_dump( $_FILES );//apenas para debug

    $servidor = 'x.x.x.x';
    $caminho_absoluto = '/home/teste/';
    $arquivo = $_FILES['arquivo'];

    $con_id = ftp_connect($servidor) or die( 'Não conectou em: '.$servidor );
    ftp_login( $con_id, 'xxxx', 'xxx' );


    $enviado = ftp_put( $con_id, $caminho_absoluto.$arquivo['name'], $arquivo['tmp_name'], FTP_BINARY );

    if ($enviado){
        echo "Arquivo Enviando com sucesso para o Servidor: ". $servidor . "<br>Caminho do arquivo FTP ". $caminho_absoluto;
    }
}

Form:

<form action="" method="post" enctype="multipart/form-data">
    <input type="file" name="arquivo" />
    <input type="submit" name="enviar" value="Enviar" />
</form>
    
17.11.2014 / 12:33
2

You can not use move_uploaded_file to upload a file to a remote server. The easiest way to accomplish this is by using the native FTP functions of PHP.

$ftp_server = "ftp.example.com";
$ftp_user = "o_seu_username";
$ftp_pass = "a_sua_password";

$file = "path/para/o/ficheiro.txt";
$remote_file = "ficheiro.txt";

// Criar ligação
$conn_id = ftp_connect($ftp_server) or die("Não conseguiu conectar com $ftp_server"); 

// Ir para a pasta onde quer carregar o ficheiro
ftp_chdir($conn_id, '/www/site/caminho/para/a/pasta');


// Efectuar login no FTP
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
    // Carregar ficheiro para servidor remoto
    if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
       echo "Carregado com sucesso de $file\n";
    } else {
       echo "Ocorreu um problema no carregamento de $file\n";
    }
} else {
    echo "Não foi possível conectar como $ftp_user\n";
}

// Fechar conexão
ftp_close($conn_id);

Note: This code has not been tested

If there is an error, it is possible that the remote server has some type of firewall and use the following code:

// Ligar modo passivo
ftp_pasv($conn_id, true);
    
14.11.2014 / 17:20
0

move_upload_file is only for use of an uploaded file. In your case: 1-verify the right of access 2- Use copy ()

Example (php.net):

        <?php
           $file = 'example.txt';
           $newfile = 'example.txt.bak';

          if (!copy($file, $newfile))
            {
                echo "falha ao copiar $file...\n";
           }
        ?>

$ file can be a URL and $ newfile as well. Caution: copy () will not create the folder!

    
14.11.2014 / 22:08