<?
error_reporting(E_ALL);
include ('connect.php');
$toegestaan = array('jpg', 'gif', 'png', 'bmp'); //vul in deze array de toegestane extensies in gescheiden door een comma
$maxfilesize = 2; //vul hier de toegestane filesize in MB's in
$maxwidth = 800; //de maximale breedte van het geuploade bestand
$maxheight = 600; //de maximale hoogte van het geuploade bestand
$directory = "images1/"; //de map waar de upload in moeten komen, inclusief slashes
$tabelnaam = "uploads"; //de naam van de tabel waar de upload in moet komen
?>
<html>
<head>
<title>Upload Script:</title>
</head>
<body>
<?php
error_reporting(E_ALL);
//code alleen uitvoeren wanneer er op submit is geklikt:
if(!empty($_POST["veld"]))
if(isset($_POST['submit'])) {
if($_POST['title'] == "") {
echo("<script language=\"javascript\">alert('U bent vergeten de title in te vullen');</script>"); }
else{
if($_POST['description'] == "") {
echo("<script language=\"javascript\">alert('U bent vergeten een description in te vullen');</script>"); }
else{
if($_POST['color'] == "") {
echo("<script language=\"javascript\">alert('U bent vergeten een color in te vullen');</script>"); }
else{
if($_POST['sizes'] == "") {
echo("<script language=\"javascript\">alert('U bent vergeten een size in te vullen');</script>"); }
else{
if($_POST['price'] == "") {
echo("<script language=\"javascript\">alert('U bent vergeten de price in te vullen');</script>"); }
else{
if($_FILES['file']['name'] == "") {
echo("<script language=\"javascript\">alert('U bent vergeten een file te selecteren');</script>"); }
else{
//extensies controleren:
$extensie = explode(".", $_FILES['file']['name']);
$extcount = count($toegestaan);
for($a=0;$a<$extcount;$a++) {
if(strtolower($extensie[1]) == $toegestaan[$a]) {
$extok = true;
$a = count($toegestaan);
}else{
$extok = false;
}
}
if($extok == false) {
echo("<script language=\"javascript\">alert('Deze extensie is niet geldig. Geldige extensies zijn:\\n' ");
for($b=0;$b<$extcount;$b++) {
$extup = strtoupper($toegestaan[$b]);
if($b == $extcount - 1) {
echo("$extup");
}else{
echo("$extup, ");
}
}
echo("');</script>");
}else{
//bestandsgrootte controleren:
$filesize = $_FILES['file']['size'];
$filesize2 = ("".ROUND($filesize / 1024, 1)." KB");
if($filesize > 1024) { $filesize2 = ("".ROUND($filesize2 / 1024, 1)." MB"); }
if($filesize > 1073741824) { $filesize2 = ("".ROUND($filesize2 / 1024 / 1024 / 1024, 1)." GB"); }
$maxfilesize2 = $maxfilesize * 1024 * 1024;
if($_FILES['file']['size'] > $maxfilesize2) {
echo("<script language=\"javascript\">alert('Dit bestand is te groot voor de upload\\nToegstaan: $maxfilesize MB');</script>");
}else{
//op dubbele files controleren:
$filenaam = $_FILES['file']['name'];
if(file_exists("$directory$filenaam")) {
echo("<script language=\"javascript\">alert('De bestandnaam ($filenaam) is al in gebruik');</script>");
}else{
//image size controleren:
$size = getimagesize($_FILES['file']['tmp_name']);
$width = $size[0];
$height = $size[1];
if($width > $maxwidth || $height > $maxheight) {
echo("<script language=\"javascript\">alert('Het formaat van dit bestand is niet correct.\\nMag max zijn: $maxwidth x $maxheight');</script>");
}else{
//Wanneer alles correct is, file uploaden:
$pad = $directory;
if(isset($_POST['submit'])) {
$query = "INSERT INTO $tabelnaam(title, description, color, sizes, price, datum, filenaam)
VALUES('".$_POST['title']."','".$_POST['description']."','".$_POST['color']."','".$_POST['sizes']."','".$_POST['price']."','$pad$filenaam')" or die ('FOUT in uitvoeren query');
$result = mysql_query($query);
copy($file, "$pad".$_FILES['file']['name']."") or die ('FOUT bij uploaden file');
echo("<center><font color=red>File uploaded...</font></center>");
}
}
}
}
}
}
} } }
//Het formulier:
echo("<center>
<table border=0 style=\"border-style: double; border-color=red\">
<form action=$_SERVER[PHP_SELF] method=POST name=\"uploadform\" enctype=\"multipart/form-data\">
<tr>
<td>Titel:</td>
<td><Input type=textbox name=title size=25 maxlength=35></td>
</tr>
<tr>
<td>Description:</td>
<td><Input type=textbox name=description size=25 maxlenght=100></td>
</tr>
<tr>
<td>Kleur</td>
<td><input type=textbox name=color size=25 maxlength=35</td>
</tr>
<tr>
<td>Maat</td>
<td><input type=textbox name=sizes size=25 maxlenght=35</td>
</tr>
<tr>
<td>Price</td>
<td><input type=textbox name=price size=25 maxlength=10</td>
<tr>
<td><input type=file name=file size=25></td>
</tr>
<tr>
<td> </td>
<td><input type=submit name=submit value=\"Upload file\"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
</center>");
?>
</body>
</html>