View Single Post
Join Date: Nov 2008
Posts: 17
Reputation: asifkamalzahid is an unknown quantity at this point 
Solved Threads: 0
asifkamalzahid asifkamalzahid is offline Offline
Newbie Poster

uploading to ftp server my directory hae some problom

 
0
  #1
Nov 21st, 2008
this is for code

  1.  
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>Untitled Document</title>
  7. </head>
  8.  
  9. <body>
  10. <form method="post" action="upload.php">
  11.  
  12. Move or Upload Folder Using PHP FTP Functions<br />
  13. </p>
  14. <table width="373" border="1">
  15. <tr>
  16. <td width="184">server address </td>
  17. <td width="173"><input type="text" id="server_name" name="server_name" /></td>
  18. </tr>
  19. <tr>
  20. <td>user name </td>
  21. <td><input type="text" name="user_name" id="user_name" /></td>
  22. </tr>
  23. <tr>
  24. <td>user password</td>
  25. <td><input type="text" id="user_password" name="user_password" /></td>
  26. </tr>
  27. <tr>
  28. <td>local directory</td>
  29. <td><input type="text" name="local_dir" id="local_dir" /></td>
  30. </tr>
  31. <tr>
  32. <td>remote directory</td>
  33. <td><input type="text" name="remote_dir" id="remote_dir" /></td>
  34. </tr>
  35. <tr>
  36. <td>&nbsp;</td>
  37. <td><input name="upload" type="submit" id="upload" /></td>
  38. </tr>
  39. </table>
  40. <p>&nbsp; </p>
  41. </form>
  42.  
  43.  
  44.  
  45.  
  46.  
  47. </body>
  48. </html>




this is the upolad page



  1.  
  2. <?php
  3. // Start the session
  4. session_start();
  5. header("Cache-control: private"); //IE 6 Fix
  6.  
  7. $_server = $_POST["server_name"];
  8. $_user_name = $_POST["user_name"];
  9. $_user_pass = $_POST["user_password"];
  10. $local_dir = $_POST["local_dir"];
  11. $remote_dir = $_POST["remote_dir"];
  12.  
  13.  
  14.  
  15. require ("uploadfunctionpage.php");
  16.  
  17.  
  18.  
  19. $uploadfunction = moveFolder($_server, $_user_name, $_user_pass, $local_dir, $remote_dir);
  20.  
  21. if($uploadfunction=true)
  22. {
  23. echo " successfull";
  24. }
  25. else
  26. {
  27. echo "failed";
  28. }
  29.  
  30.  
  31.  
  32. ?>


this is the fuction whis making connection with ftp and upolading files



  1. <?php
  2.  
  3. //Move or Upload Folder Using PHP FTP Functions
  4. function moveFolder($_server, $_user_name, $_user_pass, $local_dir, $remote_dir) {
  5.  
  6. echo"$_user_name <br/>";
  7. echo"$_user_pass <br/>";
  8. echo" directories are : <br/>";
  9. echo"$local_dir<br/>";
  10. echo"$remote_dir <br/>";
  11. $file = $remote_dir;
  12. // set up basic connection
  13. $_conn_id = ftp_connect($_server);
  14.  
  15. // login with username and password
  16. $_login_result = ftp_login($_conn_id, $_user_name, $_user_pass);
  17.  
  18. // check connection
  19. if ((!$_conn_id) || (!$_login_result)) {
  20. $_error = "FTP connection has failed!";
  21. $_error .= "Attempted to connect to $_server for user $_user_name";
  22. $result = false;
  23. } else {
  24. $_error = "Connected to $_server, for user $_user_name";
  25. }
  26.  
  27. $conn_id = $_conn_id;
  28.  
  29.  
  30.  
  31. @ftp_mkdir($conn_id, $remote_dir);
  32. echo "successfully created $remote_dir\n";
  33.  
  34. $handle = opendir($local_dir);
  35. while (($file = readdir($handle)) !== false) {
  36. if (($file != '.') && ($file != '..')) {
  37. if (is_dir($local_dir . $file)) {
  38. //recursive call
  39. moveFolder($conn_id, $local_dir . $file . '/', $remote_dir . $file . '/');
  40. echo "successfully uploaded $file\n";
  41. } else
  42. $f[] = $file;
  43. }
  44.  
  45. }
  46.  
  47.  
  48. closedir($handle);
  49. if (count($f)) {
  50. sort($f);
  51. @ftp_chdir($conn_id, $remote_dir);
  52. foreach ($f as $files) {
  53. $from = @fopen("$local_dir$files", 'r+');
  54. $moveFolder = ftp_fput($conn_id, $files, $from, FTP_ASCII);
  55. // @ftp_fput($conn_id, $files, $from, FTP_BINARY);
  56. // check upload status
  57. if (!$moveFolder) {
  58. $this->_error = "FTP upload has failed! From:" . $local_dir . " To: " . $remote_dir;
  59. $result = false;
  60. } else {
  61. $this->_error = "Uploaded $local_dir to $remote_dir as $this->_server";
  62. $result = true;
  63. }
  64. }
  65. }
  66. return $result;
  67. }
  68.  
  69. ?>
i have this error message


Warning: opendir(/c) [function.opendir]: failed to open dir: No such file or directory in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 34

Warning: readdir(): supplied argument is not a valid Directory resource in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 35

Warning: closedir(): supplied argument is not a valid Directory resource in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 48

Notice: Undefined variable: f in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 49

Notice: Undefined variable: result in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 66
successfullPHP Warning: opendir(/c) [function.opendir]: failed to open dir: No such file or directory in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 34 PHP Warning: readdir(): supplied argument is not a valid Directory resource in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 35 PHP Warning: closedir(): supplied argument is not a valid Directory resource in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 48 PHP Notice: Undefined variable: f in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 49 PHP Notice: Undefined variable: result in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 66





Reply With Quote