PHP > MySQL billede komprimering og upload - need a help!
Jeg har fået brygget flg. script sammen (egt. sammensat af to forskellige som jeg har fundet her på eksperten), fordi jeg udover almindelig billede upload også har brug for at komprimere billederne lidt.. Der ser bare ikke helt ud til at virke, så ville lgie høre alle eksperternes forslag til hvordan det lige kan rettes til så det virker (har ikke så meget check på billede upload i php):<?php
if($_POST["upload_submit"]){
if($_FILES['img_upload']['size'] > 512000){
$status = "Picture size is too big. The limit is 0,5 megabyte - try another.";
}else{
$picture = $_FILES["img_upload"]["tmp_name"];
$width = 200;
$height = 200;
list($width_orig, $height_orig) = getimagesize($picture);
if ($width && ($width_orig < $height_orig)) {
$width = ($height / $height_orig) * $width_orig;
} else {
$height = ($width / $width_orig) * $height_orig;
}
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($picture);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagejpeg($image_p, "img_db.jpg", 80);
print "$img_db<br>";
if (is_uploaded_file($img_db)) {
$data = addslashes(fread(fopen($img_db,"r"),filesize($img_db)));
$type = addslashes($_FILES['img_upload']['type']);
mysql_query("INSERT INTO house_img (house_id, image, filetype, width, height, description) values ('$_SESSION[house_id]', '$data','$type','$width','$height','$img_desc')") or die(mysql_error());
} else {
$status = "Possible file upload attack. Filename: " . $HTTP_POST_FILES['img_upload']['name'];
}
}
}
?>
