By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,327 Members | 2,627 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,327 IT Pros & Developers. It's quick & easy.

ftp upload error

P: n/a
hi all

i posted a little while ago about this, but am getting no further ahead.
does anybody have a clue as to why this script doesn't upload my files any
longer (all it does is stick a 1kb file on the server which can't be read).
i'm not sure if the script thinks the file is only 1kb large or if the
problem is somewhere else. the server is freeBSD, PHP version 4. any
ideas? tks.

if(isSet($_POST['cmdUpload'])){
$sTargetDir = trim($HTTP_POST_VARS['destDir']);
$sOriginalFileName = $HTTP_POST_FILES['srcFile']['name'];
$sImgPrefix = trim($HTTP_POST_VARS['imgCategory']);
if($sTargetDir == "/public_html/images/" || $sTargetDir ==
"/public_html/ezine/images/"){ // it's an image - attach the image category
prefix //
$sFileName = $sImgPrefix . str_replace(" ", "_", $sOriginalFileName);
}
else{
$sFileName = str_replace(" ", "_", $sOriginalFileName);
}
$sFolder = str_replace("/public_html/", "", $sTargetDir);
$sFullDestinationPath = $sTargetDir . $sFileName;
if($_POST['destDir'] == ""){
die("Error: No destination directory selected. Upload aborted. Please
click your back button and try again.");
}
else{
$oFTPConn = ftp_connect($sFtpServer,21,9600) or die("Unable to connect to
$sFTPServer!"); //login to the ftp server and upload the file //
$cmdLogin = ftp_login($oFTPConn, $sFtpUserName, $sFtpPassWord) or
die("Unable to connect to login to the FTP server: $sFTPServer!");
$cmdUpload = FTP_NB_PUT($oFTPConn, $sFullDestinationPath,
$_POST['srcFile'], FTP_BINARY);
while ($cmdUpload == FTP_MOREDATA){
$cmdUpload = FTP_NB_CONTINUE($oFTPConn);
}
$cmdCloseFTP = ftp_close($oFTPConn);
if (!$cmdUpload){ //check to see if the file was successfully uploaded //
$sResponseMsg = "<h1>Error</h1><p>Unable to upload file to server.</p>";
}
else{
$sResponseMsg = "<span style='text-decoration:
underline;'>$sFileName</span> was uploaded successfull to $sTargetDir.";
}
}
}
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Nancy Drew wrote:
does anybody have a clue as to why this script doesn't upload my files any
longer (all it does is stick a 1kb file on the server which can't be read).
i'm not sure if the script thinks the file is only 1kb large or if the
problem is somewhere else. the server is freeBSD, PHP version 4. any
ideas? tks.
<snip> $sOriginalFileName = $HTTP_POST_FILES['srcFile']['name']; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
<snip> $cmdUpload = FTP_NB_PUT($oFTPConn, $sFullDestinationPath,
$_POST['srcFile'], FTP_BINARY);

^^^^^^^^^^^^^^^^^
<snip>

Isn't < $_POST['scrFile'] > an array?

Doesn't ftp_nb_put() take a string as its third parameter?

When you have an array and treat is as a string the result can be
misleading :-)

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Jul 17 '05 #2

P: n/a

"Pedro Graca" <he****@dodgeit.com> wrote in message
news:sl*******************@ID-203069.user.uni-berlin.de...
Nancy Drew wrote:
does anybody have a clue as to why this script doesn't upload my files any longer (all it does is stick a 1kb file on the server which can't be read). i'm not sure if the script thinks the file is only 1kb large or if the
problem is somewhere else. the server is freeBSD, PHP version 4. any
ideas? tks.
<snip>
$sOriginalFileName = $HTTP_POST_FILES['srcFile']['name'];

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
<snip>
$cmdUpload = FTP_NB_PUT($oFTPConn, $sFullDestinationPath,
$_POST['srcFile'], FTP_BINARY);

^^^^^^^^^^^^^^^^^
<snip>

Isn't < $_POST['scrFile'] > an array?


yeah, that was the problem. tks pedro.
Doesn't ftp_nb_put() take a string as its third parameter?

When you have an array and treat is as a string the result can be
misleading :-)

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.