<?

include("mysql/mysql.php");

//
// Start: Tjekker om alle felter er udfyldt
//

//
// Slut: Tjekker om alle felter er udfyldt
//

//
// Start: Upload image
//

$ok=0;
if($_FILES["image"]["name"]) {
$size = $_FILES["image"]["size"] / 1024;
if($size > 0 && $size < 1023) {
$fra = $_FILES["image"]["tmp_name"];
$fra2 = $_FILES["image"]["name"];
$tilp = $_FILES["image"]["type"];
$tiltype = strstr($_FILES["image"]["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 = "filer/".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='Fil over 1 MB';} 
}else {$error='Ingen fil fundet';} 

//
// End: Upload image
//

if ($ok) {
$id = $row["id"];
$name = $row["name"];
$image = $row["image"];
mysql_query("INSERT INTO figurer_avis (name, image, type) VALUES ('$_POST[name]', '$img', '$_POST[type]')");
mysql_close();
echo "figuren er tilføjet";
}
else {
echo "Kunne ikke tilføjes, pga.:<br>".$error;
}
?>
<br><br>
<b><a href="tilfoej.php">Tilføj en figur mere</a></b>
<html>
<head>
<link rel="stylesheet" HREF="style.css" type="text/css">	
</head>
</html>