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='uploadFil e'>
<br><br>
<input name='Upload' type='submit' value='Upload'>
</form>
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +++
And here is the code in 'ftp.php' :
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ ++
// set up basic connection
$ftp_server="xx x.xxx.xxx.xxx";
$ftp_user_name= "xxx";
$ftp_user_pass= "xxx";
$source_file=$_ POST['uploadFile'];
$destination_fi le="test.jpg";
$conn_id = ftp_connect($ft p_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>Attemp ted to connect to '<b>$ftp_server </b>', as user
'<b>$ftp_user_n ame</b>'";
exit;
} else {
echo "<br>Connec ted to '<b>$ftp_server </b>', as user
'<b>$ftp_user_n ame</b>'";
}
// upload the file
$upload = ftp_fput($conn_ id, $destination_fi le, $source_file,
FTP_BINARY);
// check upload status
if (!$upload) {
echo "<br>FTP upload has failed!";
} else {
echo "<br>Upload ed '<b>$source_fil e</b>' to
'<b>$ftp_server </b>' as '<b>$destinatio n_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_fi le, $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\som e_file.jpg)
So what am I doing wrong? how can I get this to work? I am at a loss!
Cheers in advance,
Eclectic.
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='uploadFil e'>
<br><br>
<input name='Upload' type='submit' value='Upload'>
</form>
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +++
And here is the code in 'ftp.php' :
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ ++
// set up basic connection
$ftp_server="xx x.xxx.xxx.xxx";
$ftp_user_name= "xxx";
$ftp_user_pass= "xxx";
$source_file=$_ POST['uploadFile'];
$destination_fi le="test.jpg";
$conn_id = ftp_connect($ft p_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>Attemp ted to connect to '<b>$ftp_server </b>', as user
'<b>$ftp_user_n ame</b>'";
exit;
} else {
echo "<br>Connec ted to '<b>$ftp_server </b>', as user
'<b>$ftp_user_n ame</b>'";
}
// upload the file
$upload = ftp_fput($conn_ id, $destination_fi le, $source_file,
FTP_BINARY);
// check upload status
if (!$upload) {
echo "<br>FTP upload has failed!";
} else {
echo "<br>Upload ed '<b>$source_fil e</b>' to
'<b>$ftp_server </b>' as '<b>$destinatio n_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_fi le, $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\som e_file.jpg)
So what am I doing wrong? how can I get this to work? I am at a loss!
Cheers in advance,
Eclectic.
Comment