Solved

PHP FTP change destination path

Posted on 2007-04-10
2
316 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP_POST() error message 9 41
Session timeout 5 13
Bootstrap collapse causes odd behavior with php loop 7 22
Scope of $_SESSION 17 27
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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…

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now