<? include_once("db.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>
<head>
<title>Superbolig.dk</title>
<link rel="STYLESHEET" type="text/css" href="../../designet/menu.css"/>
<style type="text/css">
.td1{
border-left:1px solid #848282;
border-right:1px solid #848282;
border-top:1px solid #848282;
border-bottom:1px solid #848282;
background-color:#FFFFFF;
padding:2px;
text-align:left;
margin-left: 15px;
margin-right: 15px;
margin-top: 15px;
margin-bottom: 15px;
}
.td2{
border-left:1px solid #848282;
border-right:1px solid #848282;
border-top:1px solid #848282;
border-bottom:1px solid #848282;
background-color:#FFFFFF;
padding:2px;
text-align:left;
}
.table1 {
background-color: #FFFFFF;
border-bottom: 1px solid;
border-top: 1px solid;
border-left: 1px solid;
border-right: 1px solid;
border-color: #848282;
border-collapse: collapse;
}
.text1 {
color: #000000;
font-family: Verdana;
font-size: 8pt;
}
</style>
</head>
<body bgcolor="#9FA3AA">
<table width="436" border="0" align="center" class="table1">
</td>
</tr>
<tr>
<td style="height:350px;" valign="top">
<table class="td1" style="width:436px;height:320px;"><tr><td valign="top">
<?php
open();
$foresp = mysql_query("SELECT count(nr) AS antal FROM billeder WHERE annonce_id='$HTTP_GET_VARS[nr]'");
$res = mysql_fetch_array($foresp);
if ($res["antal"] == '3') {
echo '<BR><BR>Du har uploadet 3 billeder - hvilket er maximum. Slet evt. et af dem hvis du vil have et andet op!';
close();
} else {
if ($_POST['submit']) {
//stien, hvortil filer skal uploades, her et subdir til roden af domænet
$dist = "/home/web/php1004/rasmusblach.dk/superbolig/upload/";
//FLERE FILER PÅ SAMME TID
if (isset($_FILES["upfile"])) {
echo"<BR><BR><BR>Ønskede filer til upload:<p>\n";
$antal = 0;
$filetyper = array("image/gif", "image/jpeg", "image/pjpeg", "image/png");
$maxsize = "102400";
//Find antallet af filer til upload med en for-løkke
for($i = 0; $i < count($_FILES["upfile"]["name"]); $i++) {
if ($_FILES["upfile"]["name"][$i] !="") {
//Læg en til $antal for hver fil.
$antal++;
if (in_array($_FILES['upfile']['type'][$i], $filetyper) && $_FILES['upfile']['size'][$i] < $maxsize) {
if(is_uploaded_file($_FILES["upfile"]["tmp_name"][$i])) {
move_uploaded_file($_FILES["upfile"]["tmp_name"][$i], $dist . $_FILES["upfile"]["name"][$i]);
// adskiller filnavn fra filtype
$ext = explode(".", $_FILES["upfile"]["name"][$i]);
$newName = mt_rand(time(), 1). "_" . $HTTP_GET_VARS[nr] . "." . $ext[1];
rename($dist . $_FILES["upfile"]["name"][$i], $dist."".$newName);
//til brug for info om filtyper
$str1 = $newName;
$str2 = $_FILES["upfile"]["size"][$i];
$str3 = $_FILES["upfile"]["type"][$i];
//gemmer oplysninger i databasen
open();
$insertSQL = "INSERT INTO billeder (annonce_id, fil_navn, type, size) values ('$HTTP_GET_VARS[nr]', '$str1', '$str3', '$str2')";
mysql_query($insertSQL);
mysql_query("UPDATE annonce_udlejer SET billeder = 'ja' WHERE nr LIKE '$HTTP_GET_VARS[nr]'");
close();
echo "Filen er blevet uploadet!<BR>";
}else{
echo"Upload til serveren skete ikke!";
}
} else {
echo"Filtypen ikke tilladt til upload eller den er for stor...";
}
}
}
if($antal < 1) { //Hvis der ingen filer er valgt
echo"Husk at vælg en eller flere filer til upload!";
}else{
}
}
} else {
echo '
<form enctype="multipart/form-data" METHOD=post action="'.$php_self.'">
<DIV CLASS="normal">Vælg en eller flere filer til upload:<BR>';
open();
$foresp = mysql_query("SELECT count(nr) AS antal FROM billeder WHERE annonce_id='$HTTP_GET_VARS[nr]'");
$res = mysql_fetch_array($foresp);
if ($res["antal"] > '0') {
if ($res["antal"] == '1') {
echo '<input name="upfile[]" type="file" size="48" class="button"><br>
<input name="upfile[]" type="file" size="48" class="button"><br><p>';
}
if ($res["antal"] == '2') {
echo '<input name="upfile[]" type="file" size="48" class="button"><br>';
}
} else {
echo '<input name="upfile[]" type="file" size="48" class="button"><br>
<input name="upfile[]" type="file" size="48" class="button"><br>
<input name="upfile[]" type="file" size="48" class="button"><br><p>';
}
echo '<input type="submit" name="submit" value="Upload" class="button"></center><p>
</form>';
close();
}
}
?>
</td> </tr></table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>