FTP upload question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lammspillning
Forum Newbie
Posts: 14
Joined: Fri Aug 17, 2007 10:50 am

FTP upload question

Post by lammspillning »

When this is on my server, how would I write the path ($source_file) to a file on my local computer?
And how can I put the file inside my created folder?

Code: Select all

<?php
// set up basic connection
$conn_id = ftp_connect("ftp.mysite.com"); 
 
// login with username and password
$login_result = ftp_login($conn_id, "user", "pass"); 
 
// check connection
if ((!$conn_id) || (!$login_result)) { 
        echo "Failed!";
        exit; 
    } else {
        echo "Connected";
    }
 
$source_file = 'path to my file on local computer';
$destination_file = 'destinationName.avi';
 
// Destination directory
$dir = $_SERVER['DOCUMENT_ROOT'].'/uploadedFiles/'; 
 
// Make directory
$newFolder = mkdir($dir.'myFolder',0777);
 
// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY); 
 
// check upload status
if (!$upload) { 
        echo "FTP upload has failed!";
    } else {
        echo "Uploaded";
    }
 
// close the FTP stream 
ftp_close($conn_id); 
?>
Post Reply