PHP: upload samt resize-script
Hvorfor virker dette script ikke? Den melder en fejl når jeg loader siden:<?
if(is_uploaded_file($_FILES['minfil']['tmp_name']))
{
function resizeImage($src_file, $dest_file, $maxSize) {
$imginfo = @getimagesize($src_file);
if ($imginfo == NULL) return false;
$srcWidth = $imginfo[0];
$srcHeight = $imginfo[1];
if (($srcWidth > $maxSize) || ($srcHeight > $maxSize)) {
if ($srcWidth >= $srcHeight) {
$scale = $srcWidth/$maxSize;
}
elseif ($srcWidth < $srcHeight) {
$scale = $srcHeight/$maxSize;
}
else {
return false;
}
}
else {
$scale = 1;
}
$newWidth = round($srcWidth/$scale, 0);
$newHeight = round($srcHeight/$scale, 0);
$src_img = imagecreatefromjpeg($src_file);
$dst_img = imagecreatetruecolor($newWidth, $newHeight);
ImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $newWidth, $newHeight, $srcWidth, $srcHeight);
imagejpeg($dst_img, $dest_file, 100);
imagedestroy($src_img);
imagedestroy($dst_img);
return $dest_file;
}
$tid = time();
mysql_query("INSERT INTO images (date, keywords, mainphoto, selection) VALUES (NOW(), '$keywords', '$mainphoto', '$selection')") OR DIE(mysql_error());
$navn = mysql_insert_id();
$destinationpath = "Images/$navn.jpg";
if (move_uploaded_file($_FILES['minfil']['tmp_name'], $destinationpath))
{
$div = $_FILES['minfil']['tmp_name'];
resizeImage("$div", "Images/$navn-main.jpg", "350");
resizeImage("$div", "Images/$navn-thumb.jpg", "240");
}
else
{
?>
<form action="<? $_server['php_self']; ?>" method="post" enctype="multipart/form-data">
<font color="#808080">Vælg billede:</font> <input type="file" name="minfil" style="outline: none; border: 1px solid #000000;"><br>
<font color="#808080">Keywords:</font> <input type="text" size="30" name="keywords" style="outline: none; border: 1px solid #000000;"><br><br><font color="#808080">Forsidebillede?</font>
<input type="checkbox" name="mainphoto"> <br><br><font color="#808080">Artist's selection</font> <input type="checkbox" name="selection"><br><br><br>
<input type="submit" value="Upload fil">
</form>
<?
}
?>