Solved

PHP FTP change destination path

Posted on 2007-04-10
2
324 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

622 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