Lid |
|
Hi all,
Ik ben mijn uploadify script wat aan het uitbreiden. En ik zou graag hebben dat mijn afbeelding wat verkleind wordt na het uploaden.
Maar vreemd genoeg, gebeurt dit niet...
Mijn afbeelding wordt geupload en daarna wordt de bestandsnaam in de db opgeslagen. Maar het resize gedeelte krijg ik niet aan de praat. Weet iemand hoe dat zou komen? Aub!
<?php
include("config.php");
$id = $_REQUEST['id'];
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
$targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
move_uploaded_file($tempFile,$targetFile);
$datum = time();
$query_ = "INSERT INTO fotos (ID, album_ID, path, datum) VALUES ('', '".$id."', 'afbeeldingen/".$_FILES['Filedata']['name']."', '".$datum."')";
mysql_query($query_) or die (mysql_error());
$ext = strtolower(strrchr(basename("afbeeldingen/".$_FILES['Filedata']['name']),'.'));
$filename = "afbeeldingen/".$_FILES['Filedata']['name'];
$width = 600;
$height = 600;
list($width_orig, $height_orig) = getimagesize($filename);
if (!isset($width_orig) OR !isset($height_orig)){
$width_orig = 640;
$height_orig = 480;
}
if (($width_orig < $width) && ($height_orig < $height )){
//Klein plaatje
$width = $width_orig ;
$height = $height_orig;
}else{
$ratio_orig = $width_orig/$height_orig;
if ($width/$height > $ratio_orig) {
$width = $width*$ratio_orig;
} else {
$height = $width/$ratio_orig;
}
}
$image_p = imagecreatetruecolor($width, $height);
switch ($ext){
case ".gif":
$image = imagecreatefromgif($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagegif($image_p, 'afbeeldingen/'.$_FILES['Filedata']['name']);
break;
case ".png":
$image = imagecreatefrompng($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagepng($image_p, 'afbeeldingen/'.$_FILES['Filedata']['name']);
break;
default:
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagejpeg($image_p, 'afbeeldingen/'.$_FILES['Filedata']['name'], 75);
}
imagedestroy($image_p);
echo str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile);
}
?>
<?php include("config.php"); $id = $_REQUEST['id']; $tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/'; $targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name']; $query_ = "INSERT INTO fotos (ID, album_ID, path, datum) VALUES ('', '".$id."', 'afbeeldingen/".$_FILES['Filedata']['name']."', '".$datum."')"; $filename = "afbeeldingen/".$_FILES['Filedata']['name']; $width = 600; $height = 600; $width_orig = 640; $height_orig = 480; } if (($width_orig < $width) && ($height_orig < $height )){ //Klein plaatje $width = $width_orig ; $height = $height_orig; }else{ $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = $width*$ratio_orig; } else { $height = $width/$ratio_orig; } } $image_p = imagecreatetruecolor($width, $height); switch ($ext){ case ".gif": $image = imagecreatefromgif($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); imagegif($image_p, 'afbeeldingen/'.$_FILES['Filedata']['name']); break; case ".png": $image = imagecreatefrompng($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); imagepng($image_p, 'afbeeldingen/'.$_FILES['Filedata']['name']); break; default: $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); imagejpeg($image_p, 'afbeeldingen/'.$_FILES['Filedata']['name'], 75); } imagedestroy($image_p); } ?>
|