<?

include("../forb.php");

//
// Start: Upload image
//

$ok=0;
if($_FILES["billede"]["name"]) {
$size = $_FILES["billede"]["size"] / 1024;
if($size > 0 && $size < 1023) {
$fra = $_FILES["billede"]["tmp_name"];
$fra2 = $_FILES["billede"]["name"];
$tilp = $_FILES["billede"]["type"];
$tiltype = strstr($_FILES["billede"]["type"],"/");
$tiltype = substr($tiltype,1);
if ($tiltype == "bmp" || $tiltype == "gif" || $tiltype == "pjpeg" || $tiltype == "x-png") {
$tiltype = str_replace("x-png","png",$tiltype);
$tiltype = str_replace("pjpeg","jpg",$tiltype);
$til = "billeder/".time().rand(0000,9979)."-".$fra2;
if(function_exists("move_uploaded_file")) {
move_uploaded_file($fra, $til);
$img = "$til";
$ok=1;
} else {
copy($fra, $til);
$img = "$til";
$ok=1;
}
}else {$error='Forkert fil-format';} 
}else {$error='Filen fylder over 1 MB';} 
}else {$error='Ingen fil fundet';} 

//
// End: Upload image
//

if ($ok) {
$id = $row["id"];
$navn = $row["navn"];
$vaerdi = $row["vaerdi"];
$type = $row["type"];
$image = $row["billede"];
$info = $row["info"];
mysql_query("INSERT INTO baggrunde (navn, vaerdi, type, billede, info) VALUES ('$_POST[navn]', '$_POST[vaerdi]', '$_POST[type]', '$img', '$_POST[info]')");
mysql_close();
echo "Baggrunden er tilføjet!";
}
else {
echo "Kunne ikke tilføjes, pga.:<br>".$error;
}
?>

