ftp_nb_put() resulting in wierd file contents

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mattcooper
Forum Contributor
Posts: 210
Joined: Thu Mar 17, 2005 5:51 am
Location: London, UK

ftp_nb_put() resulting in wierd file contents

Post by mattcooper »

Hi all,

I'm using the following code to upload a user-specified file (of image, audio or video filetype) to a server that is remote to the one that hosts the script.

Code: Select all

ftp_pasv($ftpConn,true);
			$ftp = ftp_chdir($ftpConn,$ftp->userFilePath.'/'.$fileType) or die(error::errorReport('changeDirFail'));
			$ftp = ftp_nb_put($ftpConn,$fileName,$configs['mediaserver'].$_SESSION['pcu_username'].'/'.$fileType,FTP_BINARY) or die(error::errorReport('fileFTPFail'));
			
			while ($ftp == FTP_MOREDATA) {
				
			   $ftp = ftp_nb_continue($ftpConn);
			
			}
			if ($ftp != FTP_FINISHED) {
			   echo _FTP_FAIL_ ;
			   exit(1);
			}
			$ftp = ftp_close($ftpConn);
			if($ftp) echo "transfer complete";
The transfer is not working properly. Although a file with the correct name is created in the correct place on the remote server, the contents (regardless of filetype) are always the HTML you would expect to see for a directory index listing.

Can anyone suggest why this may be happening and what can be done to fix it?

Many thanks,

Matt
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Matt,

Why are you evaluating a CONSTANT in a while loop?

Code: Select all

while ($ftp == FTP_MOREDATA)
Post Reply