Error in uploading file via ftp server

Thread Solved

Join Date: Sep 2008
Posts: 13
Reputation: hirts_gal is an unknown quantity at this point 
Solved Threads: 0
hirts_gal hirts_gal is offline Offline
Newbie Poster

Error in uploading file via ftp server

 
0
  #1
Sep 22nd, 2008
i currently working on web based ftp system where this system will upload and retrieve file from ftp server in red hat linux 9.0.
here is the php cording for the upload file:-

1.upload.html
  1. <html>
  2. <head>
  3. <title>Untitled Document</title>
  4. <meta http-equiv="Content-Type" content="text/html;
  5. charset=iso-8859-1">
  6. </head>
  7. <body>
  8. <form action="upload.php" method="post" enctype="multipart/form-data" name="form1" >
  9. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  10. <tr>
  11. <td>user name </td>
  12. <td><input name="username" type="text" id="username"></td>
  13. <td>&nbsp;</td>
  14. </tr>
  15. <tr>
  16. <td>password</td>
  17. <td><input name="password" type="password" id="password"></td>
  18. <td>&nbsp;</td>
  19. </tr>
  20. <tr>
  21. <td>File name </td>
  22. <td><input type="file" name="file"></td>
  23. <td>&nbsp;</td>
  24. </tr>
  25. <tr>
  26. <td><input type="submit" name="Submit" value="Upload"></td>
  27. <td>&nbsp;</td>
  28. <td>&nbsp;</td>
  29. </tr>
  30. </table>
  31. </form>
  32. </body>
  33. </html>
2.upload.php
  1. <html>
  2. <head>
  3. <title>Untitled Document</title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  5. </head>
  6. <body>
  7. <?php
  8. //$ftp_server=$_POST['server'];
  9. $ftp_server = "10.1.45.21";
  10. $ftp_user_name=$_POST['username'];
  11. $ftp_user_pass=$_POST['password'];
  12. $source_file=$_FILES['file']['name'];// retrieve name of the file to be uploaded
  13. $destination_file=$source_file;
  14. // make a connection to the ftp server
  15. $conn_id = ftp_connect($ftp_server);
  16.  
  17. // login with username and password
  18. $login_result = ftp_login($conn_id , $ftp_user_name , $ftp_user_pass);
  19.  
  20. // check connection
  21. if((!$conn_id)||(!$login_result)){
  22. echo "FTP connection has failed!" ;
  23. echo "Attempted to connect to $ftp_server for user $ftp_user_name" ;
  24. exit;
  25. }else{
  26. echo "Connected to $ftp_server, for user $ftp_user_name" ;
  27. }
  28.  
  29.  
  30. // upload the file
  31. $upload = ftp_put($conn_id,$destination_file,$source_file,FTP_ASCII );
  32.  
  33. // check upload status
  34. if(!$upload){
  35. echo "FTP upload has failed!" ;
  36. }else{
  37. echo "Uploaded $source_file to $ftp_server as $destination_file" ;
  38. }
  39.  
  40. // close the FTP stream
  41. ftp_close($conn_id);
  42. ?>
  43. </body>
  44. </html>

when i execute this code it give me the following error:-

Connected to 10.1.45.21, for user sanya
Warning: ftp_put(forum.txt) [function.ftp-put]: failed to open stream: No such file or directory in D:\AppServ2\AppServ\www\FTP\test\upload.php on line 32
FTP upload has failed!

Can any one help me plz..
Last edited by cscgal; Sep 22nd, 2008 at 12:51 pm. Reason: Added code tags
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 821
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 135
Sponsor
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Practically a Posting Shark

Re: Error in uploading file via ftp server

 
0
  #2
Sep 22nd, 2008
$source_file is just the name of the file. The file has not yet been moved to a permanent location using move_uploaded_file(). You'll have to do that first.
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 13
Reputation: hirts_gal is an unknown quantity at this point 
Solved Threads: 0
hirts_gal hirts_gal is offline Offline
Newbie Poster

Re: Error in uploading file via ftp server

 
0
  #3
Sep 22nd, 2008
i did as you said but it still does not work. here is the cording that i add in upload.php file before close the ftp connection:-

// upload the file
//$upload = ftp_put($conn_id,$destination_file,$source_file,FTP_ASCII );
if (move_uploaded_file($source_file, "/home/admin")) {
print "Received {$_FILES['file']['name']} - its size is {$_FILES['file']['size']}";
} else {
print "Upload failed!";
}
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 13
Reputation: hirts_gal is an unknown quantity at this point 
Solved Threads: 0
hirts_gal hirts_gal is offline Offline
Newbie Poster

Re: Error in uploading file via ftp server

 
0
  #4
Sep 22nd, 2008
if i use the cording below replace the cording that i post previously:-

$destination_dir = 'home/admin';
$destination_file = $uploaddir . basename($_FILES['file']['name']);
if (move_uploaded_file($source_file, $destination_file)) {
print "Received {$_FILES['file']['name']} - its size is {$_FILES['file']['size']}";
} else {
print "Upload failed!";
}

it give me a successful message showing that the file upload successfully. but if i try to search the file in /home/admin dir in linux....there were no files there.is my upload file works and where do i check for the uploaded files. help me plz..
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 13
Reputation: hirts_gal is an unknown quantity at this point 
Solved Threads: 0
hirts_gal hirts_gal is offline Offline
Newbie Poster

Re: Error in uploading file via ftp server

 
0
  #5
Sep 23rd, 2008
i success in uploading file to FTP server. i use the cording below:-

$destination_dir = $_SERVER['DOCUMENT_ROOT'];
$destination_file = $uploaddir . basename($_FILES['file']['name']);
$upload = ftp_put($conn_id,$destination_file,$source_file,FTP_ASCII );

thank you pritaeas.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC