Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Fotki miniaturki - problem z przesłaniem do skryptu.
mariusz g
post
Post #1





Grupa: Zarejestrowani
Postów: 76
Pomógł: 0
Dołączył: 25.03.2006

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


Witam (IMG:http://forum.php.pl/style_emoticons/default/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. ?>
Go to the top of the page
+Quote Post

Posty w temacie


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: 15.09.2025 - 18:39