Witam. Chce napisać skrypt który mi zapisze na serwerze dwa rodzaje obrazków (duże i małe). Napisałem sobie skrypt trochę użyłem pomocy z innych skryptów. Niestety skrypt nie chce mi zapisać pliku na serwer oraz zmienić rozmiar. Przesiedziałem przy tym pare godzin i nadal nie wiem co moze być zle..

Poniżej pokazuje wam funkcje i skrypt

  1. <?php
  2.  
  3. function createthumbnail($filetype, $origfile, $thumbfile, $new_w, $new_h) {
  4.  
  5. global $settings;
  6.  
  7. if ($filetype == 1) { $origimage = imagecreatefromgif($origfile); }
  8. elseif ($filetype == 2) { $origimage = imagecreatefromjpeg($origfile); }
  9. elseif ($filetype == 3) { $origimage = imagecreatefrompng($origfile); }
  10.  
  11. $old_x = imagesx($origimage);
  12. $old_y = imagesy($origimage);
  13.  
  14. if ($old_x > $new_w || $old_y > $new_h) {
  15. if ($old_x < $old_y) {
  16. $thumb_w = round(($old_x * $new_h) / $old_y);
  17. $thumb_h = $new_h;
  18. } elseif ($old_x > $old_y) {
  19. $thumb_w = $new_w;
  20. $thumb_h = round(($old_y * $new_w) / $old_x);
  21. } else {
  22. $thumb_w = $new_w;
  23. $thumb_h = $new_h;
  24. }
  25. } else {
  26. $thumb_w = $old_x;
  27. $thumb_h = $old_y;
  28. }
  29.  
  30. if ("gd2" == "gd1") {
  31. $thumbimage = imagecreate($thumb_w,$thumb_h);
  32. $result = imagecopyresized($thumbimage, $origimage, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
  33. } else {
  34. $thumbimage = imagecreatetruecolor($thumb_w,$thumb_h);
  35. $result = imagecopyresampled($thumbimage, $origimage, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
  36. }
  37.  
  38. touch($thumbfile);
  39.  
  40. if ($filetype == 1) { imagegif($thumbimage, $thumbfile); }
  41. elseif ($filetype == 2) { imagejpeg($thumbimage, $thumbfile); }
  42. elseif ($filetype == 3) { imagepng($thumbimage, $thumbfile); }
  43. }
  44.  
  45. function image_exists($dir, $image) {
  46. $i = 1;
  47. $image_name = substr($image, 0, strrpos($image, "."));
  48. $image_ext = strrchr($image,".");
  49. while (file_exists($dir.$image)) {
  50. $image = $image_name."_".$i.$image_ext;
  51. $i++;
  52. }
  53. return $image;
  54. }
  55. ?>


  1. <?php
  2. require_once("manicore.php");
  3. require_once("header.php");
  4. require_once("include/photo_functions_include.php");
  5.  
  6.  
  7. if (isset($_POST['uploadimage'])) {
  8. $photo_title = stripinput($_POST['photo_title']);
  9. $photo_source = stripinput($_POST['photo_source']);
  10. $photo_file = ""; $photo_thumb1 = ""; $photo_thumb2 = "";
  11.  
  12. if (is_uploaded_file($_FILES['myfile']['tmp_name'])) {
  13. $photo_types = array(".gif",".jpg",".jpeg",".png");
  14. $photo_pic = $_FILES['myfile'];
  15. $photo_name = strtolower(substr($photo_pic['name'], 0, strrpos($photo_pic['name'], ".")));
  16. $photo_ext = strtolower(strrchr($photo_pic['name'],"."));
  17. $photo_dest = "http://localhost/test/uploads/";
  18.  
  19.  
  20. if (!preg_match("/^[-0-9A-Z_\.\[\]]+$/i", $photo_pic['name'])) {
  21. $error = "error1";
  22. } elseif ($photo_pic['size'] > 4150000){
  23. $error = "error2";
  24. } elseif (!in_array($photo_ext, $photo_types)) {
  25. $error = "error3";
  26. } else {
  27. $photo_file = image_exists($photo_dest, $photo_name.$photo_ext);
  28. move_uploaded_file($photo_pic['tmp_name'], $photo_dest.$photo_file);
  29. chmod($photo_dest.$photo_file, 0644);
  30. $imagefile = @getimagesize($photo_dest.$photo_file);
  31. if ($imagefile[0] > 2000 || $imagefile[1] > 2000) {
  32. $error = "error4";
  33. unlink($photo_dest.$photo_file);
  34. } else {
  35. $photo_thumb1 = image_exists($photo_dest, $photo_name."_t1".$photo_ext);
  36. createthumbnail($imagefile[2], $photo_dest.$photo_file, $photo_dest.$photo_thumb1, 100, 100);
  37. if ($imagefile[0] > 500 || $imagefile[1] > 1100) {
  38. $photo_thumb2 = image_exists($photo_dest, $photo_name."_t2".$photo_ext);
  39. createthumbnail($imagefile[2], $photo_dest.$photo_file, $photo_dest.$photo_thumb2, 500, 1100);
  40. }
  41. }
  42. }
  43. }
  44.  
  45. }
  46.  
  47. ?>