Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Skrypt php
Forum PHP.pl > Forum > PHP
janemba
Witam
Chciałbym wstawić na stronkę możliwość wysłania plików na serwer na którym stoi stronka. php znam w bardzo małym stopniu. Udało mi się odnaleźć kod, lecz jest z nim błąd.
  1. <?php
  2. //-- SMTP Mail Function By Aditya Bhatt
  3. if(isset($_POST['SubmitFile'])){
  4. $myFile = $_FILES['txt_file']; // This will make an array out of the file information that was stored.
  5. $file = $myFile['tmp_name']; //Converts the array into a new string containing the path name on the server where your file is.
  6.  
  7. $myFileName = basename($_FILES['txt_file']['name']); //Retrieve filename out of file path
  8.  
  9. $destination_file = $_REQUEST['filepath'].$myFileName;
  10. #"/developers/uploadftp/aditya/".$myFileName; //where you want to throw the file on the webserver (relative to your login dir)
  11.  
  12. // connection settings
  13. $ftp_server = trim($_REQUEST['serverip']); //address of ftp server.
  14. $ftp_user_name = trim($_REQUEST['username']); // Username
  15. $ftp_user_pass = trim($_REQUEST['password']); // Password
  16.  
  17. $conn_id = ftp_connect($ftp_server) or die("<span style='color:#FF0000'><h2>Couldn't connect to $ftp_server</h2></span>"); // set up basic connection
  18. #print_r($conn_id);
  19. $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) or die("<span style='color:#FF0000'><h2>You do not have access to this ftp server!</h2></span>"); // login with username and password, or give invalid user message
  20. if ((!$conn_id) || (!$login_result)) { // check connection
  21. // wont ever hit this, b/c of the die call on ftp_login
  22. echo "<span style='color:#FF0000'><h2>FTP connection has failed!
  23. ";
  24. echo "Attempted to connect to $ftp_server for user $ftp_user_name</h2></span>";
  25. exit;
  26. } else {
  27. // echo "Connected to $ftp_server, for user $ftp_user_name
  28. ";
  29. }
  30.  
  31. $upload = ftp_put($conn_id, $destination_file, $file, FTP_BINARY); // upload the file
  32. if (!$upload) { // check upload status
  33. echo "<span style='color:#FF0000'><h2>FTP upload of $myFileName has failed!</h2></span>
  34. ";
  35. } else {
  36. echo "<span style='color:#339900'><h2>Uploading $myFileName Completed Successfully!</h2></span>
  37.  
  38. ";
  39. }
  40.  
  41. ftp_close($conn_id); // close the FTP stream
  42. }
  43. ?>
  44.  
  45. <html>
  46. <head></head>
  47. <body>
  48. <form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
  49. Server IP Address: <input name="serverip" type="text" id="serverip" size="15" value=""/>
  50.  
  51. Server Username: <input name="username" type="text" id="username" size="15" value=""/>
  52.  
  53. Server Password: <input name="password" type="text" id="password" size="15" value=""/>
  54.  
  55. Server File Path: <input name="filepath" type="text" id="filepath" size="35" value=""/>
  56.  
  57. Please choose a file: <input name="txt_file" type="file" id="txt_file" tabindex="1" size="35" onchange="txt_fileName.value=txt_file.value" />
  58.  
  59.  
  60. <input name="txt_fileName" type="hidden" id="txt_fileName" tabindex="99" size="1" />
  61.  
  62. <input type="submit" name="SubmitFile" value="Upload File" accesskey="ENTER" tabindex="2" />
  63. </form>
  64. </body>
  65. </html>
Błąd jest następujący
Kod
Parse error: syntax error, unexpected T_STRING in /var/www/sites/yoyo.pl/q/u/quppe/index.html on line 33
Strona stoi na yoyo, jest obsługa php i mysql. Czy mógłby mi ktoś poprawić ten kod ? Mam też darmowy serwer zagraniczny na który przerzucę całość jak będzie gotowa.
Pozdrawiam

Naprawdę nikt nie zna odpowiedzi na to pytanie... ?
athei
Linia 27 i 28 źle zakomentowałeś.
Żle
Kod
// echo "Connected to $ftp_server, for user $ftp_user_name
";
Dobrze
Kod
// echo "Connected to $ftp_server, for user $ftp_user_name";
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.