Billede-upload - Find fejlen
Jeg kan ikke få denne til at virke. Den uploader fint det store af billederne, men ikke det lille (thumb).Hvad har jeg gjort forkert?
<?
$uploaddir = "billeder/"; // Mappe til færdige billeder
$maxsize = 365; // Maximum bredde/højde
$maxsize_thumb = 115; // Maximum bredde/højde
if (isset($_POST['submit']) && $_POST['submit'] == "Send Fil") {
$source = $_FILES['upfile']['tmp_name'];
$name = $_FILES['upfile']['name'];
$name_thumb = "thumb_" . $name;
if (is_uploaded_file($source)) {
if (tjektype($name)) {
$dest = $uploaddir . $name;
$dest = tjekfil($dest);
$dest_thumb = $uploaddir . $name_thumb;
if (move_uploaded_file($source, $dest)) {
thumb($dest, $maxsize);
thumb($dest_thumb, $maxsize_thumb);
echo "Upload ok!";
echo "<p><img src='".$dest."' alt='billede' /></p>";
echo "<p><img src='".$dest_thumb."' alt='thumb' /></p>";
include("conn.php");
$insertSQL = "insert into biler (billede1, billede_thumb1, info)
values ('$dest', '$dest_thumb', '$info')";
mysql_query($insertSQL) or die(mysql_error());
} else {
echo "Ingen upload!";
}
} else {
echo "Denne filtype er ikke tilladt at uploade!";
}
} else {
echo "Ulovlig handling!";
}
}
function Thumb($sourcefile, $size) {
$ext = strrchr($sourcefile, '.');
if ($ext == '.png') {
$im = imageCreateFromPNG($sourcefile);
} elseif ($ext == '.jpg' || $ext == '.jpeg') {
$im = imageCreateFromJPEG($sourcefile);
}
$source_x = imagesx($im);
$source_y = imagesy($im);
$delta = $size/max($source_x, $source_y);
$dest_x = round($source_x*$delta);
$dest_y = round($source_y*$delta);
$target_id = imagecreatetruecolor($dest_x, $dest_y);
imagecopyresampled($target_id,$im,0,0,0,0, $dest_x,$dest_y, $source_x,$source_y);
$black = imagecolorallocate ($target_id, 0, 0, 0);
imagecolortransparent($target_id, $black);
if ($ext == '.png') {
imagePNG($target_id, $sourcefile);
} elseif ($ext == '.jpg' || $ext == '.jpeg') {
imageJPEG($target_id, $sourcefile);
}
}
function tjektype($filnavn) {
$ext = strrchr($filnavn, '.');
$tilladt = array('.jpg', '.jpeg', '.png');
if(!in_array($ext, $tilladt)) {
return false;
}else{
return true;
}
}
function tjekfil($filnavn) {
$i = 0;
$arr = explode(".", $filnavn);
$ext = array_pop($arr);
$navn = implode(".", $arr);
$navn = str_replace(' ', '_', $navn);
while (is_file($filnavn)) {
$i++;
$filnavn = $navn . "_" . sprintf("%06u", $i) . "." . $ext;
}
return $filnavn;
}
?>
