Link to home
Start Free TrialLog in
Avatar of mshirazi1
mshirazi1

asked on

PHP FTP change destination path

Hi,
I created a ftp connection via php but can't change the destination path.
In the following example $md is my destination file and it only works when I have it set to the root folder.
($md = "./"). However, the actual folder where I want to place the files is ./images/temp. When I try
$md = "./images/temp";, I get a "Call to a member function on a non-object" error. Does anyone know how to change the destination path from ./ to ./images/temp?

Thanks,
Ross


<?php
// set up basic connection
$ftp_server = "mypath";
$ftp_user_name = "username";
$ftp_user_pass = "pass";

$conn_id = ftp_connect($ftp_server);

// 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";
        exit;
    } else {
        echo "Connected to $ftp_server, for user $ftp_user_name";
    }

// upload the file
$md = "./";
   while(($file = $mydir->read()) !== false) {
      echo "Filename: $file<BR>";
        $upload = ftp_put($conn_id, $file, $md, FTP_BINARY);

      if (!$upload) {
              echo "FTP upload has failed!";
       } else {
              echo "Uploaded $file to $ftp_server to $md";
       }
   }
   $mydir->close();
ftp_close($conn_id);
?>
Avatar of steelseth12
steelseth12
Flag of Cyprus image

ftp_chdir($conn_id, "images/temp")

// upload the file
$md = "name of remote file";
ASKER CERTIFIED SOLUTION
Avatar of steelseth12
steelseth12
Flag of Cyprus image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial