Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Fotki miniaturki - problem z przesłaniem do skryptu.
Forum PHP.pl > Forum > Przedszkole
mariusz g
Witam exclamation.gif!

Chce przesłać do skryptu wybraną fotkę.
Jeśli jest w tym samym katalogu i method="get" to jest oki -- tylko dla fotki z tego samego katalogu. A jeśli jest method="post" to wartość zmiennej oka jest taka: C:\DOCUME~1\Mariusz\USTAWI~1\Temp\php27.tmp

Co zrobić żeby działało z innego katalogu ?

a to kod
  1. <form action="index.php" method="post" enctype="multipart/form-data">
  2.  
  3. <input type="file" name="oka" size="20">
  4. <input type="submit" value="Wyślij">
  5. </form>
  6.  
  7.  
  8.  
  9.  
  10. <?php
  11.  
  12. print $oka;
  13. print"<br /><br /><br />";
  14.  
  15. function imgType($name)
  16. {
  17.  if(substr($name, -4, 4) == '.jpg' || substr($name, -4, 4) == 'jpeg')
  18.  {
  19. return IMAGETYPE_JPEG;
  20.  }
  21.  elseif(substr($name, -4, 4) == '.gif')
  22.  {
  23. return IMAGETYPE_GIF;
  24.  }
  25.  elseif(substr($name, -4, 4) == '.png')
  26.  {
  27. return IMAGETYPE_PNG;
  28.  }
  29. }
  30.  
  31. function resizeImage($source, $max_x, $max_y, $save_image, $jpeg_quality = 100)
  32. {
  33.  
  34.  
  35. if(imgType($source) == IMAGETYPE_JPEG)
  36. {
  37.  $img_src = imagecreatefromjpeg($source);
  38. }
  39. elseif(imgType($source) == IMAGETYPE_GIF)
  40. {
  41.  $img_src = imagecreatefromgif($source);
  42. }
  43. elseif(imgType($source) == IMAGETYPE_PNG)
  44. {
  45.  $img_src = imagecreatefrompng($source);
  46. }
  47. else
  48. {
  49.  die('Wrong filetype! Accepted images: JPG/JPEG, GIF, PNG');
  50. }
  51.  
  52.  $image_x = imagesx($img_src);
  53.  $image_y = imagesy($img_src);
  54.  
  55.  
  56.  
  57.  if($image_x > $image_y) // Landscape
  58.  {
  59. $ratio_x = ($image_x > $max_x) ? $max_x/$image_x : 1;
  60. $ratio_y = $ratio_x;
  61. $move = 'y';
  62.  }
  63.  else // Portrait
  64.  {
  65. $ratio_y = ($image_y > $max_y) ? $max_y/$image_y : 1;
  66. $ratio_x = $ratio_y;
  67. $move = 'x';
  68.  }
  69. $new_x = $image_x*$ratio_x;
  70. $new_y = $image_y*$ratio_y;
  71.  
  72. $move_x = ($move == "x") ? ($max_x-$new_x)/: 0;
  73. $move_y = ($move == "y") ? ($new_y-$new_y)/: 0;// z new na max_y
  74.  
  75. $new_img = imagecreatetruecolor($max_x, $new_y);///zmiana max_y
  76. $background = imagecolorallocate($new_img, 155, 155, 155);
  77. imagefill($new_img, 0, 0, $background);
  78. imagecopyresampled($new_img, $img_src, $move_x, $move_y, 0, 0, $new_x, $new_y, $image_x, $image_y);
  79.  
  80. if(imgType($save_image) == IMAGETYPE_JPEG)
  81. {
  82.  imagejpeg($new_img, $save_image, 100);
  83. }
  84. elseif(imgType($save_image) == IMAGETYPE_GIF)
  85. {
  86.  imagegif($new_img, $save_image);
  87. }
  88. elseif(imgType($save_image) == IMAGETYPE_PNG)
  89. {
  90.  imagepng($new_img, $save_image);
  91. }
  92.  
  93.  echo "<img src="".$save_image."" border="1">";
  94.  
  95.  
  96. }
  97.  
  98. resizeImage($oka, 120, 160, 'nowafotka.jpg', 56); 
  99.  
  100. ?>
Mike122
  1. <?php
  2. function imgType($name)
  3. {
  4.  if(substr($name, -4, 4) == '.jpg' || substr($name, -4, 4) == 'jpeg')
  5.  {
  6. return IMAGETYPE_JPEG;
  7.  }
  8.  elseif(substr($name, -4, 4) == '.gif')
  9.  {
  10. return IMAGETYPE_GIF;
  11.  }
  12.  elseif(substr($name, -4, 4) == '.png')
  13.  {
  14. return IMAGETYPE_PNG;
  15.  }
  16. }
  17.  
  18. function resizeImage($source, $max_x, $max_y, $save_image, $jpeg_quality = 100)
  19. {
  20.  
  21.  
  22. if(imgType($source) == IMAGETYPE_JPEG)
  23. {
  24.  $img_src = imagecreatefromjpeg($source);
  25. }
  26. elseif(imgType($source) == IMAGETYPE_GIF)
  27. {
  28.  $img_src = imagecreatefromgif($source);
  29. }
  30. elseif(imgType($source) == IMAGETYPE_PNG)
  31. {
  32.  $img_src = imagecreatefrompng($source);
  33. }
  34. else
  35. {
  36.  die('Wrong filetype! Accepted images: JPG/JPEG, GIF, PNG');
  37. }
  38.  
  39.  $image_x = imagesx($img_src);
  40.  $image_y = imagesy($img_src);
  41.  
  42.  
  43.  
  44.  if($image_x > $image_y) // Landscape
  45.  {
  46. $ratio_x = ($image_x > $max_x) ? $max_x/$image_x : 1;
  47. $ratio_y = $ratio_x;
  48. $move = 'y';
  49.  }
  50.  else // Portrait
  51.  {
  52. $ratio_y = ($image_y > $max_y) ? $max_y/$image_y : 1;
  53. $ratio_x = $ratio_y;
  54. $move = 'x';
  55.  }
  56. $new_x = $image_x*$ratio_x;
  57. $new_y = $image_y*$ratio_y;
  58.  
  59. $move_x = ($move == "x") ? ($max_x-$new_x)/: 0;
  60. $move_y = ($move == "y") ? ($new_y-$new_y)/: 0;// z new na max_y
  61.  
  62. $new_img = imagecreatetruecolor($max_x, $new_y);///zmiana max_y
  63. $background = imagecolorallocate($new_img, 155, 155, 155);
  64. imagefill($new_img, 0, 0, $background);
  65. imagecopyresampled($new_img, $img_src, $move_x, $move_y, 0, 0, $new_x, $new_y, $image_x, $image_y);
  66.  
  67. if(imgType($save_image) == IMAGETYPE_JPEG)
  68. {
  69.  imagejpeg($new_img, $save_image, 100);
  70. }
  71. elseif(imgType($save_image) == IMAGETYPE_GIF)
  72. {
  73.  imagegif($new_img, $save_image);
  74. }
  75. elseif(imgType($save_image) == IMAGETYPE_PNG)
  76. {
  77.  imagepng($new_img, $save_image);
  78. }
  79.  
  80.  echo "<img src="".$save_image."" border="1">";
  81.  
  82.  
  83. }
  84.  
  85.  
  86. $oka = $_POST['oka'];
  87.  
  88. if ($url){
  89. print '<form action="index.php" method="post" enctype="multipart/form-data">';
  90. print '<input type="file" name="oka" size="20">';
  91. print '<input type="submit" value="Wyślij">';
  92. print '</form>';
  93. print"<br /><br /><br />";
  94. resizeImage($oka, 120, 160, 'nowafotka.jpg', 56); 
  95. }else{
  96. print '<form action="index.php" method="post" enctype="multipart/form-data">';
  97. print '<input type="file" name="oka" size="20">';
  98. print '<input type="submit" value="Wyślij">';
  99. print '</form>';
  100. }
  101. ?>

Spróbuj tak rolleyes.gif
mariusz g
Po kliknięciu wyślij powraca do tego samego formularza i z fotką nic nie robi i tak bez końca.
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.