Solved

PHP FTP change destination path

Posted on 2007-04-10
2
318 Views
Last Modified: 2008-02-20
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);
?>
0
Comment
Question by:mshirazi1
  • 2
2 Comments
 
LVL 20

Expert Comment

by:steelseth12
ID: 18883229
ftp_chdir($conn_id, "images/temp")

// upload the file
$md = "name of remote file";
0
 
LVL 20

Accepted Solution

by:
steelseth12 earned 250 total points
ID: 18883245
sorry $md should be the name if the local file ....

so this line would be   $upload = ftp_put($conn_id, remote file, local file, FTP_BINARY);
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question