here is part of the FTP upload script I made... it should at least get your started...
$ftp_address = "ftp.whereyourgoing.com";
$ftp_username = "username";
$ftp_password = "secretpassword";
function open_ftp_connection () {
GLOBAL $ftp_address, $ftp_username, $ftp_password;
if (isset($GLOBALS['ftp']) && $GLOBALS['ftp']){
return $GLOBALS['ftp'];
} else {
// connect to server:
$ftp = ftp_connect($ftp_address);
if (!$ftp){
error_page("didn't connect to the ftp server.");
}
// login to ftp server
$ftp_login = ftp_login($ftp, $ftp_username, $ftp_password);
if (!$ftp_login){
error_page('could not login to the ftp server.');
}
$mode = ftp_pasv($ftp, 1);
$GLOBALS['ftp'] = $ftp;
return $ftp;
}
}
// this function will take a remote file (stored wherever on the internet), open it, and then pass the open file (which is now just a file pointer) to upload_open_file() which will then upload it via FTP.
// format: string upload_remote_file (string $remote_file [, string $dest_dir [, string $dest_name]])
// returns destination address if completed successfully
// outputs error if there is a problem
function upload_remote_file($remote_file){
$extension = strtolower(strrchr($remote_file, '.'));
$num_args = func_num_args();
if ($num_args > 2){
$change_to = func_get_arg(2);
} else {
// put default directory here.
$change_to = "";
}
if ($num_args > 3){
$name = func_get_arg(3);
} else {
// put the default file name here:
$name = "temp.x";
}
$fp = fopen($remote_file, 'r');
$filename = upload_open_file($fp, $extension, $change_to, $name);
return $filename;
}
// this function will take an open file (in the form of a file pointer) and upload it via FTP, after it uses open_ftp_connection to connect to the ftp server.
// format: string upload_open_file (fp $file, string $extension [, string $dest_dir [, string $dest_name]])
// returns destination address if completed successfully
// outputs error if there is a problem
function upload_open_file ($file, $extension){
$num_args = func_num_args();
if ($num_args > 2){
$change_to = func_get_arg(2);
} else {
// put default directory here
$change_to = "";
}
if ($num_args > 3){
$name = func_get_arg(3) . $extension;
} else {
// put the default name of the file here.
$name = "temp.x";
}
$ftp = open_ftp_connection();
$upload = ftp_fput($ftp, $change_to . $name, $file, FTP_BINARY);
if (!$upload){
error_page('could not upload ' . $name . '!');
}
return $name;
}
/* example usage:
$temp_file = tmpfile();
$test = "this will be the contents of the test file";
fwrite($temp_file, $test);
$filename = upload_open_file($temp_file);
fclose($temp_file); // optional really...
echo("you have succesfully uploaded the file: $filename");
----- or ------
$remote_file = "http://a.file.you.want.to.upload.somewhere.com/file.jpg";
$filename = upload_remote_file($remote_file, "/pictures/", "test.jpg");
echo("you have successfully uploaded the file: $filename");
*/
that should be a great start for you. If you're trying to upload from a form and into an FTP server, I have some more code to complete that process, but you may be able to fill in the rest yourself.