943,535 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 3215
  • PHP RSS
Sep 22nd, 2008
0

Error in uploading file via ftp server

Expand Post »
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
php Syntax (Toggle Plain Text)
  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
php Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hirts_gal is offline Offline
13 posts
since Sep 2008
Sep 22nd, 2008
0

Re: Error in uploading file via ftp server

$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.
Sponsor
Featured Poster
Reputation Points: 549
Solved Threads: 722
Bite my shiny metal ass!
pritaeas is offline Offline
4,156 posts
since Jul 2006
Sep 22nd, 2008
0

Re: Error in uploading file via ftp server

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!";
}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hirts_gal is offline Offline
13 posts
since Sep 2008
Sep 22nd, 2008
0

Re: Error in uploading file via ftp server

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..
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hirts_gal is offline Offline
13 posts
since Sep 2008
Sep 23rd, 2008
0

Re: Error in uploading file via ftp server

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hirts_gal is offline Offline
13 posts
since Sep 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: combobox problems
Next Thread in PHP Forum Timeline: PHP/JavaScript Problem...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC