Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [HTML][PHP]Inputy zmienne
mateŁusz
post
Post #1





Grupa: Zarejestrowani
Postów: 102
Pomógł: 0
Dołączył: 21.08.2012

Ostrzeżenie: (0%)
-----


Kolejny post, w którym muszę Was prosić o pomoc, gdyż nie wiem jak zrobić to, że np. jest taki formularz:


  1. Sygnatura:
  2. <select>
  3. <option>Sygnatura 1</option>
  4. <option>Sygnatura 2</option>
  5. <option>Sygnatura 3</option>
  6. </select>


Formularz odnosi się do pliku PHP.
Chcę, aby było zrobione to tak, aby po wybraniu "Sygnatura 1" korzystało z pliku "1.png", po "Sygnatura 2" - "2.png", po "Sygnatura 3" - "3.png".
Jak to zrobić na zmiennych, aby z tych option przekazywało zmienną jakoś do pliku PHP do:

  1. $rysunek = ImageCreateFromPng("Tutaj jakoś zmienna aby było te "1.png""2.png""3.png" w zależności co wybierzemy w formularzu");


Cały kod PHP:

  1. <?php
  2.  
  3. $rysunek = ImageCreateFromPng("1.png");
  4. $nickkolor = ImageColorAllocate($rysunek, 24, 116, 205);
  5. $levelkolor = ImageColorAllocate($rysunek, 28, 134, 238);
  6. $krolestwokolor = ImageColorAllocate($rysunek, 0, 191, 255);
  7. $gildiakolor = ImageColorAllocate($rysunek, 0, 191, 255);
  8.  
  9. $font = "fonts/arial.ttf";
  10. $x = "30";
  11. $y = "200";
  12. $x1 = "160";
  13. $y1 = "30";
  14. $x2 = "190";
  15. $y2 = "50";
  16. $x3 = "220";
  17. $y3 = "70";
  18. $nachylenie = "1";
  19. $rozmiar = "3";
  20. $rozmiar1a = "10";
  21. $rozmiar1 = "15";
  22. $rozmiar3 = "17";
  23. $rozmiar2 = "20";
  24. $nick = $_POST['nick'];
  25. $level = $_POST['level'];
  26. $krolestwo = $_POST['krolestwo'];
  27. $gildia = $_POST['gildia'];
  28.  
  29. imagettftext($rysunek, "$rozmiar3", "90", "$x", "$y", $nickkolor, $font, "Nick: $nick");
  30. imagettftext($rysunek, "$rozmiar2", "$nachylenie", "$x1", "$y1", $levelkolor, $font, "Level: $level");
  31. imagettftext($rysunek, "$rozmiar1", "$nachylenie", "$x2", "$y2", $krolestwokolor, $font, "Krolestwo: $krolestwo");
  32. imagettftext($rysunek, "$rozmiar1a", "$nachylenie", "$x3", "$y3", $gildiakolor, $font, "Gildia: $gildia");
  33.  
  34.  
  35. header('Content-Disposition: attachment; filename="sygna.png"');
  36. imagePNG($rysunek);
  37.  
  38.  
  39. ?>


Ten post edytował mateŁusz 24.11.2012, 13:28:14
Go to the top of the page
+Quote Post
vifus
post
Post #2





Grupa: Zarejestrowani
Postów: 109
Pomógł: 13
Dołączył: 7.04.2012

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




  1. Sygnatura:
  2. <select name="syg">
  3. <option value="1.png">Sygnatura 1</option>
  4. <option value="2.png">Sygnatura 2</option>
  5. <option value="3.png">Sygnatura 3</option>
  6. </select>


  1. <?php
  2. $syg=$_POST['syg'];
  3. $rysunek = ImageCreateFromPng($syg);
  4. $nickkolor = ImageColorAllocate($rysunek, 24, 116, 205);
  5. $levelkolor = ImageColorAllocate($rysunek, 28, 134, 238);
  6. $krolestwokolor = ImageColorAllocate($rysunek, 0, 191, 255);
  7. $gildiakolor = ImageColorAllocate($rysunek, 0, 191, 255);
  8.  
  9. $font = "fonts/arial.ttf";
  10. $x = "30";
  11. $y = "200";
  12. $x1 = "160";
  13. $y1 = "30";
  14. $x2 = "190";
  15. $y2 = "50";
  16. $x3 = "220";
  17. $y3 = "70";
  18. $nachylenie = "1";
  19. $rozmiar = "3";
  20. $rozmiar1a = "10";
  21. $rozmiar1 = "15";
  22. $rozmiar3 = "17";
  23. $rozmiar2 = "20";
  24. $nick = $_POST['nick'];
  25. $level = $_POST['level'];
  26. $krolestwo = $_POST['krolestwo'];
  27. $gildia = $_POST['gildia'];
  28.  
  29. imagettftext($rysunek, "$rozmiar3", "90", "$x", "$y", $nickkolor, $font, "Nick: $nick");
  30. imagettftext($rysunek, "$rozmiar2", "$nachylenie", "$x1", "$y1", $levelkolor, $font, "Level: $level");
  31. imagettftext($rysunek, "$rozmiar1", "$nachylenie", "$x2", "$y2", $krolestwokolor, $font, "Krolestwo: $krolestwo");
  32. imagettftext($rysunek, "$rozmiar1a", "$nachylenie", "$x3", "$y3", $gildiakolor, $font, "Gildia: $gildia");
  33.  
  34.  
  35. header('Content-Disposition: attachment; filename="sygna.png"');
  36. imagePNG($rysunek);
  37.  
  38.  
  39. ?>
Go to the top of the page
+Quote Post
mateŁusz
post
Post #3





Grupa: Zarejestrowani
Postów: 102
Pomógł: 0
Dołączył: 21.08.2012

Ostrzeżenie: (0%)
-----


Mógłby ktoś jeszcze przerobić ten kod, aby było można wybrać kolor, np. biały, czarny, czerwony, pomarańczowy? RGB.
Go to the top of the page
+Quote Post
vifus
post
Post #4





Grupa: Zarejestrowani
Postów: 109
Pomógł: 13
Dołączył: 7.04.2012

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


No to analogicznie do poprzedniego przykładu...

  1. kolor:
  2. <select name="kolor">
  3. <option value="50, 205, 50">zielony</option>
  4. <option value="0, 0, 156">niebieski</option>
  5. <option value="255, 0, 0">czerwony</option>
  6. </select>




  1. <?php
  2. $syg=$_POST['syg'];
  3. $kolor=$_POST['kolor'];
  4. $rysunek = ImageCreateFromPng($syg);
  5. $nickkolor = ImageColorAllocate($rysunek, $kolor);
  6. $levelkolor = ImageColorAllocate($rysunek, 28, 134, 238);
  7. $krolestwokolor = ImageColorAllocate($rysunek, 0, 191, 255);
  8. $gildiakolor = ImageColorAllocate($rysunek, 0, 191, 255);
  9.  
  10. $font = "fonts/arial.ttf";
  11. $x = "30";
  12. $y = "200";
  13. $x1 = "160";
  14. $y1 = "30";
  15. $x2 = "190";
  16. $y2 = "50";
  17. $x3 = "220";
  18. $y3 = "70";
  19. $nachylenie = "1";
  20. $rozmiar = "3";
  21. $rozmiar1a = "10";
  22. $rozmiar1 = "15";
  23. $rozmiar3 = "17";
  24. $rozmiar2 = "20";
  25. $nick = $_POST['nick'];
  26. $level = $_POST['level'];
  27. $krolestwo = $_POST['krolestwo'];
  28. $gildia = $_POST['gildia'];
  29.  
  30. imagettftext($rysunek, "$rozmiar3", "90", "$x", "$y", $nickkolor, $font, "Nick: $nick");
  31. imagettftext($rysunek, "$rozmiar2", "$nachylenie", "$x1", "$y1", $levelkolor, $font, "Level: $level");
  32. imagettftext($rysunek, "$rozmiar1", "$nachylenie", "$x2", "$y2", $krolestwokolor, $font, "Krolestwo: $krolestwo");
  33. imagettftext($rysunek, "$rozmiar1a", "$nachylenie", "$x3", "$y3", $gildiakolor, $font, "Gildia: $gildia");
  34.  
  35.  
  36. header('Content-Disposition: attachment; filename="sygna.png"');
  37. imagePNG($rysunek);
  38.  
  39.  
  40. ?>


Ten post edytował vifus 24.11.2012, 15:25:22
Go to the top of the page
+Quote Post
mateŁusz
post
Post #5





Grupa: Zarejestrowani
Postów: 102
Pomógł: 0
Dołączył: 21.08.2012

Ostrzeżenie: (0%)
-----


Robiłem już tak i nie działało, nie wiem.. może o jedną linię kodu napisałem za mało.
Dziękuję.

Nie działa, to samo co u mnie.
Zwraca błąd:
Cytat
Warning: imagecolorallocate() expects exactly 4 parameters, 2 given in E:\xampp\htdocs\astraanar\generuj.php on line 5


Kod wyżej, o 2 parametry za mało przekazuje.

Ten post edytował mateŁusz 24.11.2012, 15:35:07
Go to the top of the page
+Quote Post
IceManSpy
post
Post #6





Grupa: Zarejestrowani
Postów: 1 006
Pomógł: 111
Dołączył: 23.07.2010
Skąd: Kraków

Ostrzeżenie: (0%)
-----


Bo zmienna kolor ma 2 sobie pozostałe (czyli w 1 zmiennej, zawarte są 3), brakujące argumenty. Musisz rozbić ją (explode) względem przecinków a potem przekazać do funkcji tablice po wykonaniu funkcji explode.

Ten post edytował IceManSpy 24.11.2012, 15:41:36
Go to the top of the page
+Quote Post
mateŁusz
post
Post #7





Grupa: Zarejestrowani
Postów: 102
Pomógł: 0
Dołączył: 21.08.2012

Ostrzeżenie: (0%)
-----


(IMG:style_emoticons/default/wacko.gif)
dobra, wiem chyba.. albo nie (IMG:style_emoticons/default/biggrin.gif)
Spróbuję

#Mój pomysł zawiódł.

Chciałby ktoś mi gotowca napisać? Przekopałem połowe google i nic nie wychodzi :x

ref (IMG:style_emoticons/default/smile.gif)

Ten post edytował mateŁusz 24.11.2012, 15:47:26
Go to the top of the page
+Quote Post
MagicianVH
post
Post #8





Grupa: Zarejestrowani
Postów: 12
Pomógł: 0
Dołączył: 31.08.2010

Ostrzeżenie: (0%)
-----


Seriously?
  1. $kolor = explode(",", $_POST['kolor']);
  2. $nickkolor = ImageColorAllocate($rysunek, $kolor[0], $kolor[1], $kolor[2]);
Go to the top of the page
+Quote Post
mateŁusz
post
Post #9





Grupa: Zarejestrowani
Postów: 102
Pomógł: 0
Dołączył: 21.08.2012

Ostrzeżenie: (0%)
-----


Dobra, ja już nie wiem co jest źle..

  1. <form action="generuj.php" method="post">
  2. Sygnatura:
  3. <select name="syg">
  4. <option value="1.png">Sygnatura 1</option>
  5. <option value="2.png">Sygnatura 2</option>
  6. <option value="3.png">Sygnatura 3</option>
  7. <option value="4.png">Sygnatura 4</option>
  8. <option value="5.png">Sygnatura 5</option>
  9. </select><br>
  10. kolor:
  11. <select name="kolor">
  12. <option value="50, 205, 50">zielony</option>
  13. <option value="0, 0, 156">niebieski</option>
  14. <option value="255, 0, 0">czerwony</option>
  15. </select><br>
  16. Nick: <input type="text" name="nick" /><br />
  17. Level: <input type="text" name="level" /><br />
  18. Krolestwo:<input type="text" name="krolestwo" /><br />
  19. Gildia:<input type="text" name="gildia" /><br />
  20. <input type="submit" name="submit" value="Generuj!" />
  21. </form>



  1. <?php
  2. $syg=$_POST['syg'];
  3. $kolor=$_POST['kolor'];
  4. $kolor = explode(",", $_POST['kolor']);
  5. $nickkolor = ImageColorAllocate($rysunek, $kolor[0], $kolor[1], $kolor[2]);
  6. $rysunek = ImageCreateFromPng($syg);
  7. $levelkolor = ImageColorAllocate($rysunek, 28, 134, 238);
  8. $krolestwokolor = ImageColorAllocate($rysunek, 0, 191, 255);
  9. $gildiakolor = ImageColorAllocate($rysunek, 0, 191, 255);
  10.  
  11. $font = "fonts/arial.ttf";
  12. $x = "30";
  13. $y = "200";
  14. $x1 = "160";
  15. $y1 = "30";
  16. $x2 = "190";
  17. $y2 = "50";
  18. $x3 = "220";
  19. $y3 = "70";
  20. $nachylenie = "1";
  21. $rozmiar = "3";
  22. $rozmiar1a = "10";
  23. $rozmiar1 = "15";
  24. $rozmiar3 = "17";
  25. $rozmiar2 = "20";
  26. $nick = $_POST['nick'];
  27. $level = $_POST['level'];
  28. $krolestwo = $_POST['krolestwo'];
  29. $gildia = $_POST['gildia'];
  30.  
  31. imagettftext($rysunek, "$rozmiar3", "90", "$x", "$y", $nickkolor, $font, "Nick: $nick");
  32. imagettftext($rysunek, "$rozmiar2", "$nachylenie", "$x1", "$y1", $nickkolor, $font, "Level: $level");
  33. imagettftext($rysunek, "$rozmiar1", "$nachylenie", "$x2", "$y2", $nickkolor, $font, "Krolestwo: $krolestwo");
  34. imagettftext($rysunek, "$rozmiar1a", "$nachylenie", "$x3", "$y3", $nickkolor, $font, "Gildia: $gildia");
  35.  
  36.  
  37. header("Content-type: image/png");
  38. imagePNG($rysunek);
  39.  
  40.  
  41. ?>

  1. Warning: imagecolorallocate() expects parameter 1 to be resource, null given in E:\xampp\htdocs\astraanar\generuj.php on line 5
Go to the top of the page
+Quote Post
minolone
post
Post #10





Grupa: Zarejestrowani
Postów: 141
Pomógł: 24
Dołączył: 21.06.2008

Ostrzeżenie: (0%)
-----


usuń tutaj spacje między wartościami
Kod
<option value="50, 205, 50">zielony</option>
<option value="0, 0, 156">niebieski</option>
<option value="255, 0, 0">czerwony</option>

lub tutaj dodaj spacje po przecinku w explode
Kod
$kolor = explode(",", $_POST['kolor']);

czyli
Kod
$kolor = explode(", ", $_POST['kolor']);


i przenieś zmienną $rysunek nad $nickkolor

Ten post edytował minolone 27.11.2012, 17:17:17
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 28.08.2025 - 15:56