Solved

PHP FTP change destination path

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
The viewer will learn how to dynamically set the form action using jQuery.
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.

743 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

13 Experts available now in Live!

Get 1:1 Help Now