View Single Post
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