Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Przesyłanie pliku do serwera
nikestylex7
post
Post #1





Grupa: Zarejestrowani
Postów: 386
Pomógł: 7
Dołączył: 22.04.2010
Skąd: Ziemia

Ostrzeżenie: (20%)
X----


Witam. Temat dotyczy przesyłania plików do serwera, zmiany nazwy pliku jeśli już taki występuje.Gdyż jestem początkującym napotkałem
następujące błędy : plik nie zostaje wysłany na serwer, gdy plik występuje nie zostaje zmieniona nazwa. Oraz pytanie czy jako nazwa pliku liczy się też rozszerzenie jak tak to jak zrobić żeby zmieniało tylko nazwe.
  1.  
  2. <?
  3. print("<form enctype=\"multipart/form-data\" method=post><input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"50000\">");
  4. print("<input type=file name=avatar>");
  5. print("</form>");
  6.  
  7. if(isset($avatar)){
  8. move_uploaded_file($avatar, "./images/avatars/");
  9. if(file_exists($avatar)) {
  10. print("Plik o podanej nazwie istnieje.");
  11. for( $x = 1; $x+2; $x++ )
  12. rename($avatar, $x);
  13. print("Nazwa została zmieniona.");
  14. }
  15. else {
  16. print("Plik został załadowany.");
  17.  
  18. }
  19. }
  20. ?>

plik rejestracja_.php
  1. <?php
  2. include "baza.php";
  3. $title = 'Rejestracja';
  4. include "gora.php";
  5. define("OK", 0);
  6. define("ALL", 1);
  7. define("HASLA", 2);
  8. define("EMAILE", 3);
  9. define("REGULAMIN", 4);
  10. define("NICK", 5);
  11. define("HASLO", 6);
  12. define("EMAIL", 7);
  13. define("PEMAIL", 8);
  14. define("WP", 9);
  15. define("NAZWA_ZAJETA", 10);
  16. define("EMAIL_ZAJETY", 11);
  17. define("AVATAR", 11);
  18. function rejestruj($user, $haslo, $email, $imie, $miasto, $skype, $opis,$avatar, $plec, $data) {
  19. if(!isSet($_POST['user']) || !isSet($_POST['haslo']) || !isSet($_POST['haslo2']) || !isSet($_POST['email']) || !isSet($_POST['email2'])) {
  20. return ALL;
  21. } else if($_POST['haslo'] !== $_POST['haslo2']) {
  22. return HASLA;
  23. } else if($_POST['email'] !== $_POST['email2']) {
  24. return EMAILE;
  25. } else if(!isSet($_POST['regulamin'])) {
  26. return REGULAMIN;
  27. } else if(!isSet($_POST['avatar'])) {
  28. return AVATAR;
  29. }
  30.  
  31. $dlugoscUser = strlen($_POST['user']);
  32. $dlugoscHaslo = strlen($_POST['haslo']);
  33. $dlugoscEmail = strlen($_POST['email']);
  34.  
  35. if($dlugoscUser < 3) {
  36. return NICK;
  37. } else if($dlugoscHaslo < 6) {
  38. return HASLO;
  39. } else if($dlugoscEmail < 5) {
  40. return EMAIL;
  41. } else if(strpos($_POST['email'], '@') === false) {
  42. return PEMAIL;
  43. }
  44. include "baza.php";
  45. $query = "SELECT COUNT(*) FROM user WHERE user='$user' ";
  46.  
  47. if(!$result = mysql_query($query)) {
  48. echo('An error has occurred: Instruction SELECT...');
  49. }
  50. if(!$row = mysql_fetch_row($result)) {
  51. echo('An error has occurred: Incorrect query results...');
  52. } else {
  53. if($row[0] > 0) {
  54. return NAZWA_ZAJETA;
  55. }
  56. }
  57.  
  58. $query = "SELECT COUNT(*) FROM user WHERE email='$email' ";
  59.  
  60. if(!$result = mysql_query($query)) {
  61. echo('An error has occurred: Instruction SELECT...');
  62. }
  63. if(!$row = mysql_fetch_row($result)) {
  64. echo('An error has occurred: Incorrect query results...');
  65. } else {
  66. if($row[0] > 0) {
  67. return EMAIL_ZAJETY;
  68. }
  69. }
  70. mysql_query("INSERT INTO user SET user='$user', haslo='$haslo', email='$email', imie='$imie', miasto='$miasto', skype='$skype', opis='$opis', plec='$plec', avatar='$avatar', data_rej='$data', ip='".$_SERVER["REMOTE_ADDR"]."', kasa=20");
  71. $ranking = mysql_fetch_row(mysql_query("SELECT id FROM user WHERE user='$user'"));
  72. mysql_query("UPDATE user SET ranking='".$ranking[0]."' WHERE user='$user'");
  73.  
  74. $count = mysql_affected_rows();
  75.  
  76. if($count <> 1) {
  77. echo "Rejestracja nie powiodła się!";
  78. } else {
  79. return OK;
  80. }
  81. }
  82.  
  83. if(isSet($_SESSION['street-race'])) {
  84. echo "Nie możesz się zarejestrować jak jesteś zalogowany. Najpierw <a href='wyloguj.php'>wyloguj</a> się.";
  85. } else if(!isSet($_POST['user']) || !isSet($_POST['haslo']) || !isSet($_POST['haslo2']) || !isSet($_POST['email']) || !isSet($_POST['email2'])) {
  86. echo "Aby się zarejestrować przejdź<a href='rejestracja.php'> tutaj</a>.";
  87. } else {
  88.  
  89. $user = htmlspecialchars(trim(mb_strtolower($_POST['user'], "utf-8")));
  90. $haslo = md5(htmlspecialchars($_POST['haslo']));
  91. $email = htmlspecialchars($_POST['email']);
  92. if(isSet($_POST['imie'])) {
  93. $imie = htmlspecialchars($_POST['imie']);
  94. } else {
  95. $imie = '';
  96. }
  97. if(isSet($_POST['miasto'])) {
  98. $miasto = htmlspecialchars($_POST['miasto']);
  99. } else {
  100. $miasto = '';
  101. }
  102. if(isSet($_POST['skype'])) {
  103. $skype = (int)htmlspecialchars($_POST['skype']);
  104. } else {
  105. $skype = '';
  106. }
  107. if(isSet($_POST['opis'])) {
  108. $opis = htmlspecialchars($_POST['opis']);
  109. } else {
  110. $opis = '';
  111. }
  112. if(isSet($_POST['plec'])) {
  113. $plec = htmlspecialchars($_POST['plec']);
  114. } else {
  115. $plec = '';
  116. }
  117. if(isSet($_POST['avatar'])) {
  118. $avatar = htmlspecialchars($_POST['avatar']);
  119. } else {
  120. $avatar = 1;
  121. }
  122. $data = date("Y-m-d");
  123.  
  124. $val = rejestruj($user, $haslo, $email, $imie, $miasto, $skype, $opis,$avatar, $plec, $data);
  125.  
  126. if($val == OK) {
  127. echo("You have been correctly registered. You can now log in using your username and password.");
  128. } else if($val == ALL) {
  129. echo("Fill in all required fields! <br /><a href='java script:history.go(-1)'>back</a><br />");
  130. } else if($val == HASLA) {
  131. echo("Enter the correct two of the same password! <br /><a href='java script:history.go(-1)'>back</a><br />");
  132. } else if($val == EMAILE) {
  133. echo("Enter the correct two of the same email address! <br /><a href='java script:history.go(-1)'>back</a><br />");
  134. } else if($val == REGULAMIN) {
  135. echo("You must accept the rules! <br /><a href='java script:history.go(-1)'>back</a><br />");
  136. } else if($val == NICK) {
  137. echo("Nick must have a minimum of 3 characters! <br /><a href='java script:history.go(-1)'>back</a><br />");
  138. } else if($val == HASLO) {
  139. echo("Your password must be at least 6 characters! <br /><a href='java script:history.go(-1)'>back</a><br />");
  140. } else if($val == AVATAR) {
  141. echo("Podano złą ścieżkę! <br /><a href='java script:history.go(-1)'>back</a><br />");
  142. } else if($val == EMAIL) {
  143. echo("Your email address is incorrect! <br /><a href='java script:history.go(-1)'>back</a><br />");
  144. } else if($val == PEMAIL) {
  145. echo("Please enter a valid email address. <br /><a href='java script:history.go(-1)'>back</a><br />");
  146. } else if($val == WP) {
  147. echo("You must enter the email address from another provider, because this address does not reach you with our message because it will be considered spam. <br /><a href='java script:history.go(-1)'>back</a><br />");
  148. } else if($val == NAZWA_ZAJETA) {
  149. echo("This username is already taken! <br /><a href='java script:history.go(-1)'>back</a><br />");
  150. } else if($val == EMAIL_ZAJETY) {
  151. echo("Someone has already use this email address! <br /><a href='java script:history.go(-1)'>back</a><br />");
  152. } else {
  153. echo("Server Error. Registration failed.");
  154. }
  155. }
  156. include "dol.php";
  157. ?>


Ten post edytował nikestylex7 24.11.2010, 16:36:05
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 21.08.2025 - 17:39