Ftp upload problem
Moderator: General Moderators
Re: Ftp upload problem
Thanks, I'll keep struggling with it for a while. 
Re: Ftp upload problem
My current code again it is:
Tried chdir this time, it worked, so it seems the cwd is indeed set to /public_html/test/ftp/, but the file is not uploaded?
I provide additional info with phpinfo:
my ftp access is enabled, I can upload up to 200MB,
upload_tmp_dir and user_dir is no value? Could it be the problem?
Code: Select all
<?php
// set up ftp connection
$ftp_server="$_POST[ftp_server]";
$ftp_username="$_POST[ftp_username]";
$ftp_password="$_POST[ftp_password]";
$ftp_upload_directory="/public_html/test/ftp/";
$ftp_source_file = $_FILES['ftp_source_file']['name'];
$ftp_destination_file=$ftp_source_file;
$ftp_connection_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($ftp_connection_id, $ftp_username, $ftp_password);
// check ftp connection
if ((!$ftp_connection_id) || (!$login_result)) {
echo "<font color='red'>Error:</font> FTP connection has failed!<br>";
echo "Attempted to connect to $ftpserver for user $ftp_username";
exit;
} else {
echo "<font color='green'>Success:</font> Connected to $ftp_server, for user $ftp_username : trying to upload $ftp_upload_directory$ftp_source_file<br>";
}
//change current working directory
$ftp_do_change_working_directory=ftp_chdir($ftp_connection_id,$ftp_upload_directory);
//check ftp change dir
if (!$ftp_do_change_working_directory) {
echo "<font color='red'>Error:</font> FTP chdir has failed";
} else {
echo "<font color='green'>Success:</font> FTP chdir has succeeded! Successfully changed to $ftp_upload_directory <br>";
}
// upload the file
$ftp_do_upload = ftp_put($ftp_connection_id, $ftp_upload_directory.$ftp_destination_file, $ftp_source_file, FTP_BINARY);
// check upload status
if (!$ftp_do_upload) {
echo "<font color='red'>Error:</font> FTP upload has failed for: $ftp_source_file when trying to store as $ftp_upload_directory$ftp_destination_file<br><br>";
} else {
//successfully uploaded the file
echo "<font color='green'>Success: </font>Uploaded $source_file to $ftp_server as $destination_file <br>";
}
// close the ftp connection
ftp_close($ftp_connection_id);
?>I provide additional info with phpinfo:
my ftp access is enabled, I can upload up to 200MB,
upload_tmp_dir and user_dir is no value? Could it be the problem?
Re: Ftp upload problem
Anyways I can't seem to find a solution so I'll just use move_uploaded_file and cross my fingers.
Thanks guys and gals.
Thanks guys and gals.
Re: Ftp upload problem
That's the easiest solution - just make sure your Apache user has write access to this folder. 
There are 10 types of people in this world, those who understand binary and those who don't
Re: Ftp upload problem
heheh, I have used it before successfully, what can go wrong now?
I might even consider making a flash applet for this so I can watch the progress.
I might even consider making a flash applet for this so I can watch the progress.