Jump to content

How to upload a file to a ftp server


madspof

Recommended Posts

okay well i have made this script off the php.net site and all i need now is to figure out how to get the users file to the ftp server not the one on my server. i was thinking i might need to upload their file to mine then from there to the ftp server any way here the code

$file = 'somefile.txt';
$fp = fopen($file, 'r');

// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

$response = ftp_chdir($conn_id, "www");

// try to upload $file
if (ftp_fput($conn_id, $file, $fp, FTP_ASCII)) {
   echo "Successfully uploaded $file\n";
} else {
   echo "There was a problem while uploading $file\n";
}

// close the connection and the file handler
ftp_close($conn_id);
fclose($fp);
?> 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.