uploads in db plaatsen
Ik wil graag dat van elke foto die geupload wordt de naam in mijn database komt te staan, ik heb onderstaand script, maar krijg het maar niet voor elkaar om elke foto in de db te zetten!..
kan iemand me helpen?.
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?
$sql1 = "SELECT * FROM projecten WHERE link = '".$_GET['project']."'";
$result1 = mysql_query($sql1);
$proj1 = mysql_fetch_array($result1);
$map = "../projecten/".$_GET['project']."/"; // Map waar alles geupload wordt
function upload_file($fTmp, $fNew) {
if(file_exists($fNew)) {
return false;
} else {
copy($fTmp, $fNew);
return true;
}
}
if(IsSet($_POST['submit'])) {
for($i = 0; $i < count($_FILES['bestand']['name']); $i++) {
if(IsSet($_FILES['bestand']['name'][$i]) && is_uploaded_file($_FILES['bestand']['tmp_name'][$i])) {
if(!upload_file($_FILES['bestand']['tmp_name'][$i], $map.$_FILES['bestand']['name'][$i])) {
$error = true;
}
}
}
if(IsSet($error)) {
echo "<table width=95% cellpadding=0 cellspacing=0 border=0 style=\"BORDER: rgb(0,0,0) 1px solid;\">";
echo "<tr>";
echo "<td colspan=3 bgcolor=#C0C0C0 align=center style=\"BORDER-BOTTOM: rgb(0,0,0) 1px solid;\"><b>Upload proces</b></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Fotos zijn <b>NIET</b> geupload</td>";
echo "</tr>";
echo "</table>";
} else {
$sql = "INSERT INTO fotos (foto, project_id) VALUES ('".$_FILES['bestand']['tmp_name'][$i]."', '".$proj1['id']."')";
mysql_query($sql) or die (mysql_error());
echo "<table width=95% cellpadding=0 cellspacing=0 border=0 style=\"BORDER: rgb(0,0,0) 1px solid;\">";
echo "<tr>";
echo "<td colspan=3 bgcolor=#C0C0C0 align=center style=\"BORDER-BOTTOM: rgb(0,0,0) 1px solid;\"><b>Upload proces</b></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Fotos zijn <b>succesvol</b> geupload / ".$_FILES['bestand']['tmp_name'][$i]."</td>";
echo "</tr>";
echo "</table>";
}
} else {
if(IsSet($_POST['aantal'])) {
$aantal = $_POST['aantal'];
} else {
$aantal = 5;
}
echo "<table width=95% cellpadding=0 cellspacing=0 border=0 style=\"BORDER: rgb(0,0,0) 1px solid;\">";
echo "<tr>";
echo "<td colspan=3 bgcolor=#C0C0C0 align=center style=\"BORDER-BOTTOM: rgb(0,0,0) 1px solid;\"><b>Aantal fotos bepalen</b></td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan=3 align=center>Fotos uploaden in map: <b>".$_GET['project']."</b></td>";
echo "</tr>";
?>
$sql1 = "SELECT * FROM projecten WHERE link = '".$_GET['project']."'";
$result1 = mysql_query($sql1);
$proj1 = mysql_fetch_array($result1);
$map = "../projecten/".$_GET['project']."/"; // Map waar alles geupload wordt
function upload_file($fTmp, $fNew) {
if(file_exists($fNew)) {
return false;
} else {
copy($fTmp, $fNew);
return true;
}
}
if(IsSet($_POST['submit'])) {
for($i = 0; $i < count($_FILES['bestand']['name']); $i++) {
if(IsSet($_FILES['bestand']['name'][$i]) && is_uploaded_file($_FILES['bestand']['tmp_name'][$i])) {
if(!upload_file($_FILES['bestand']['tmp_name'][$i], $map.$_FILES['bestand']['name'][$i])) {
$error = true;
}
}
}
if(IsSet($error)) {
echo "<table width=95% cellpadding=0 cellspacing=0 border=0 style=\"BORDER: rgb(0,0,0) 1px solid;\">";
echo "<tr>";
echo "<td colspan=3 bgcolor=#C0C0C0 align=center style=\"BORDER-BOTTOM: rgb(0,0,0) 1px solid;\"><b>Upload proces</b></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Fotos zijn <b>NIET</b> geupload</td>";
echo "</tr>";
echo "</table>";
} else {
$sql = "INSERT INTO fotos (foto, project_id) VALUES ('".$_FILES['bestand']['tmp_name'][$i]."', '".$proj1['id']."')";
mysql_query($sql) or die (mysql_error());
echo "<table width=95% cellpadding=0 cellspacing=0 border=0 style=\"BORDER: rgb(0,0,0) 1px solid;\">";
echo "<tr>";
echo "<td colspan=3 bgcolor=#C0C0C0 align=center style=\"BORDER-BOTTOM: rgb(0,0,0) 1px solid;\"><b>Upload proces</b></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Fotos zijn <b>succesvol</b> geupload / ".$_FILES['bestand']['tmp_name'][$i]."</td>";
echo "</tr>";
echo "</table>";
}
} else {
if(IsSet($_POST['aantal'])) {
$aantal = $_POST['aantal'];
} else {
$aantal = 5;
}
echo "<table width=95% cellpadding=0 cellspacing=0 border=0 style=\"BORDER: rgb(0,0,0) 1px solid;\">";
echo "<tr>";
echo "<td colspan=3 bgcolor=#C0C0C0 align=center style=\"BORDER-BOTTOM: rgb(0,0,0) 1px solid;\"><b>Aantal fotos bepalen</b></td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan=3 align=center>Fotos uploaden in map: <b>".$_GET['project']."</b></td>";
echo "</tr>";
?>
<form action="" method="post">
<tr>
<td colspan=3 align=center valign=middle height=30><input type="text" name="aantal" value="" size="1"> <input type="submit" name="aantal_submit" value="Aantal bestanden"></td>
</tr>
</form>
</table>
<br>
<table width=95% cellpadding=0 cellspacing=0 border=0 style="BORDER: rgb(0,0,0) 1px solid;">
<tr>
<td colspan=3 bgcolor=#C0C0C0 align=center style="BORDER-BOTTOM: rgb(0,0,0) 1px solid;"><b>Fotos uploaden</b></td>
</tr>
<form action="" method="POST" enctype="multipart/form-data">
<tr>
<td> <img src=../layout/arrow1.gif> Bestand </td><td>:</td><td> <input type="file" name="bestand[]"></td>
</tr>
<tr>
<td colspan=3 align=center valign=middle height=30 style="BORDER-TOP: rgb(0,0,0) 1px solid;"><input type="submit" name="submit" value="Uploaden"></td>
</tr>
</table>
</form>
ik zal je bestand eens bekijken
daar zal het ongetwijfeld mee te maken hebben!. maar mijn veldje "foto" blijft leeg!..