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
<?php
function createthumbnail($filetype, $origfile, $thumbfile, $new_w, $new_h) {
if ($filetype == 1) { $origimage = imagecreatefromgif($origfile); }
elseif ($filetype == 2) { $origimage = imagecreatefromjpeg($origfile); }
elseif ($filetype == 3) { $origimage = imagecreatefrompng($origfile); }
$old_x = imagesx($origimage);
$old_y = imagesy($origimage);
if ($old_x > $new_w || $old_y > $new_h) {
if ($old_x < $old_y) {
$thumb_w = round(($old_x * $new_h) / $old_y); $thumb_h = $new_h;
} elseif ($old_x > $old_y) {
$thumb_w = $new_w;
$thumb_h = round(($old_y * $new_w) / $old_x); } else {
$thumb_w = $new_w;
$thumb_h = $new_h;
}
} else {
$thumb_w = $old_x;
$thumb_h = $old_y;
}
if ("gd2" == "gd1") {
$thumbimage = imagecreate($thumb_w,$thumb_h);
$result = imagecopyresized($thumbimage, $origimage, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
} else {
$thumbimage = imagecreatetruecolor($thumb_w,$thumb_h);
$result = imagecopyresampled($thumbimage, $origimage, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
}
if ($filetype == 1) { imagegif($thumbimage, $thumbfile); }
elseif ($filetype == 2) { imagejpeg($thumbimage, $thumbfile); }
elseif ($filetype == 3) { imagepng($thumbimage, $thumbfile); }
}
function image_exists($dir, $image) {
$i = 1;
$image = $image_name."_".$i.$image_ext;
$i++;
}
return $image;
}
?>
<?php
require_once("manicore.php");
require_once("header.php");
require_once("include/photo_functions_include.php");
if (isset($_POST['uploadimage'])) { $photo_title = stripinput($_POST['photo_title']);
$photo_source = stripinput($_POST['photo_source']);
$photo_file = ""; $photo_thumb1 = ""; $photo_thumb2 = "";
$photo_types = array(".gif",".jpg",".jpeg",".png"); $photo_pic = $_FILES['myfile'];
$photo_dest = "http://localhost/test/uploads/";
if (!preg_match("/^[-0-9A-Z_\.\[\]]+$/i", $photo_pic['name'])) { $error = "error1";
} elseif ($photo_pic['size'] > 4150000){
$error = "error2";
} elseif (!in_array($photo_ext, $photo_types)) { $error = "error3";
} else {
$photo_file = image_exists($photo_dest, $photo_name.$photo_ext);
chmod($photo_dest.$photo_file, 0644);
if ($imagefile[0] > 2000 || $imagefile[1] > 2000) {
$error = "error4";
unlink($photo_dest.$photo_file); } else {
$photo_thumb1 = image_exists($photo_dest, $photo_name."_t1".$photo_ext);
createthumbnail($imagefile[2], $photo_dest.$photo_file, $photo_dest.$photo_thumb1, 100, 100);
if ($imagefile[0] > 500 || $imagefile[1] > 1100) {
$photo_thumb2 = image_exists($photo_dest, $photo_name."_t2".$photo_ext);
createthumbnail($imagefile[2], $photo_dest.$photo_file, $photo_dest.$photo_thumb2, 500, 1100);
}
}
}
}
}
?>