Hey all,
First up, I am a newb, so go easy on me!
I am having issues with the FTP Function ... I have read MANY posts on
similar problems, but have found no fixes that seem to work (for me at
least) ...
I have pretty much cut and paste the FTP example from PHP.net. The
code connects to and logs into the FTP server fine, but never uploads
anything!
Bellow is my form code to retrieve the source file name :
++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++
<form name='ftpUpload' method='post' action='ftp.php'>
<input type='file' name='uploadFile'>
<br><br>
<input name='Upload' type='submit' value='Upload'>
</form>
++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++
And here is the code in 'ftp.php' :
++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++
// set up basic connection
$ftp_server="xxx.xxx.xxx.xxx";
$ftp_user_name="xxx";
$ftp_user_pass="xxx";
$source_file=$_POST['uploadFile'];
$destination_file="test.jpg";
$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 "<br>FTP connection has failed!";
echo "<br>Attempted to connect to '<b>$ftp_server</b>', as user
'<b>$ftp_user_name</b>'";
exit;
} else {
echo "<br>Connected to '<b>$ftp_server</b>', as user
'<b>$ftp_user_name</b>'";
}
// upload the file
$upload = ftp_fput($conn_id, $destination_file, $source_file,
FTP_BINARY);
// check upload status
if (!$upload) {
echo "<br>FTP upload has failed!";
} else {
echo "<br>Uploaded '<b>$source_file</b>' to
'<b>$ftp_server</b>' as '<b>$destination_file</b>'";
}
// close the FTP stream
ftp_close($conn_id);
++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++
The results are the same everytime. "FTP upload has failed!"
I have tried using $ftp_fput, but this generates the error "expects
parameter 3 to be resource".
So I tried opening the $source_file using :
$myFile = $fopen($source_file, 'r');
$upload = ftp_fput($conn_id, $destination_file, $myFile, FTP_BINARY);
but this returns the same error as above, and also states that the
source file does not exist - but in the location of 'ftp.php' on the
web server!! (as though I am trying to get the source file from thw
web server, despite the fact that the $source_file is the full path
and name of the file from the local machine. eg
C:\some_dir\some_file.jpg)
So what am I doing wrong? how can I get this to work? I am at a loss!
Cheers in advance,
Eclectic.