Niks toevoegen in db als foto niet geupload word
Deze voegt de naam van de geuploade foto in een db, nu si het de bedoeling dat wanneer het uploaden van een foto niet lukt hij ook niks in mijn db zet!.. ik weet alleen niet hoe ik dat moet gaan doen!.. iemand die me kan 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?<?
echo "<table width=95% cellpadding=0 cellspacing=0 border=0 style=\"BORDER: rgb(0,0,0) 1px solid;\">";
echo "<tr>";
echo "<td align=center style=\"BORDER-BOTTOM: rgb(0,0,0) 1px solid;\" bgcolor=#C0C0C0>";
echo "<b>Kies het menu</b>";
echo "</td>";
echo "</tr>";
echo "<form method=POST name=form1 action=\"\">";
echo "<tr>";
echo "<td align=center valign=middle height=40>";
echo "<select name=project onchange=\"document.getElementById('form1').submit()\">";
echo "<option selected=\"Kies een menu\">Kies een menu..</option>";
$sql = "SELECT * FROM projecten ORDER BY id DESC";
$result = mysql_query($sql);
while ($proj = mysql_fetch_array($result)) {
echo "<option value=".$proj['link'].">".$proj['naam']."</option>";
}
echo "</select>";
echo "</td>";
echo "</tr>";
echo "</table></form>";
echo "<br>";
$sql1 = "SELECT * FROM projecten WHERE link = '".$_POST['project']."'";
$result1 = mysql_query($sql1);
$proj1 = mysql_fetch_array($result1);
$map = "../projecten/".$_POST['project2']."/"; // 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])) {
$sql = "INSERT INTO fotos (foto, project_id) VALUES ('".$_FILES['bestand']['name'][$i]."', '".$_POST['project_id']."')";
mysql_query($sql) or die (mysql_error());
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 {
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 / ".$_POST['project']."</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>".$_POST['project']."</b></td>";
echo "</tr>";
echo "<form action=\"?p=projecten/fotos_uploaden&project=".$_POST['project']."\" method=\"post\">";
echo "<input type=hidden name=project value=".$_POST['project'].">";
?>
<tr>
<td colspan=3 align=center valign=middle height=30><input type="text" name="aantal" value="<?php echo $aantal; ?>" 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>
<?
echo "<form action=\"?p=projecten/fotos_uploaden&project=".$_POST['project2'] ."\" method=\"POST\" enctype=\"multipart/form-data\">";
echo "<input type=hidden name=project_id value=\"".$proj1['id']."\">";
echo "<input type=hidden name=project2 value=\"".$proj1['link']."\">";
for($i = 0; $i < $aantal; $i++) {
?>
<tr>
<td> <img src=../layout/arrow1.gif> Bestand <?php echo $i + 1; ?></td><td>:</td><td> <input type="file" name="bestand[<?php echo $i; ?>]"></td>
</tr>
<?php
}
?>
<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>
<?php
}
?>?>
echo "<table width=95% cellpadding=0 cellspacing=0 border=0 style=\"BORDER: rgb(0,0,0) 1px solid;\">";
echo "<tr>";
echo "<td align=center style=\"BORDER-BOTTOM: rgb(0,0,0) 1px solid;\" bgcolor=#C0C0C0>";
echo "<b>Kies het menu</b>";
echo "</td>";
echo "</tr>";
echo "<form method=POST name=form1 action=\"\">";
echo "<tr>";
echo "<td align=center valign=middle height=40>";
echo "<select name=project onchange=\"document.getElementById('form1').submit()\">";
echo "<option selected=\"Kies een menu\">Kies een menu..</option>";
$sql = "SELECT * FROM projecten ORDER BY id DESC";
$result = mysql_query($sql);
while ($proj = mysql_fetch_array($result)) {
echo "<option value=".$proj['link'].">".$proj['naam']."</option>";
}
echo "</select>";
echo "</td>";
echo "</tr>";
echo "</table></form>";
echo "<br>";
$sql1 = "SELECT * FROM projecten WHERE link = '".$_POST['project']."'";
$result1 = mysql_query($sql1);
$proj1 = mysql_fetch_array($result1);
$map = "../projecten/".$_POST['project2']."/"; // 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])) {
$sql = "INSERT INTO fotos (foto, project_id) VALUES ('".$_FILES['bestand']['name'][$i]."', '".$_POST['project_id']."')";
mysql_query($sql) or die (mysql_error());
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 {
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 / ".$_POST['project']."</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>".$_POST['project']."</b></td>";
echo "</tr>";
echo "<form action=\"?p=projecten/fotos_uploaden&project=".$_POST['project']."\" method=\"post\">";
echo "<input type=hidden name=project value=".$_POST['project'].">";
?>
<tr>
<td colspan=3 align=center valign=middle height=30><input type="text" name="aantal" value="<?php echo $aantal; ?>" 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>
<?
echo "<form action=\"?p=projecten/fotos_uploaden&project=".$_POST['project2'] ."\" method=\"POST\" enctype=\"multipart/form-data\">";
echo "<input type=hidden name=project_id value=\"".$proj1['id']."\">";
echo "<input type=hidden name=project2 value=\"".$proj1['link']."\">";
for($i = 0; $i < $aantal; $i++) {
?>
<tr>
<td> <img src=../layout/arrow1.gif> Bestand <?php echo $i + 1; ?></td><td>:</td><td> <input type="file" name="bestand[<?php echo $i; ?>]"></td>
</tr>
<?php
}
?>
<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>
<?php
}
?>?>
$test = move_uploaded_file();
if($test == TRUE)
{
gelukt
}else{
niet gelukt
}
Maar je zou het ook rechtstreeks kunnen aanpakken...
if (move_uploaded_file($_FILES['gebruikersbestand']['tmp_name'], $uploadedFile)) {
echo 'Upload gelukt.';
}
Maar ik kies altijd voor duidelijkheid/overzicht boven snelheid en kleine code.
Gewijzigd op 12/01/2006 20:49:00 door Arjan Kapteijn
maar op dat query verhaal!. heb jij daar een oplossng voor?.
if($test == TRUE)
{
// gelukt, dus hier voer je de query uit..
}else{
niet gelukt
}
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?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])) {
$sql = "INSERT INTO fotos (foto, project_id) VALUES ('".$_FILES['bestand']['name'][$i]."', '".$_POST['project_id']."')";
mysql_query($sql) or die (mysql_error());
if(!upload_file($_FILES['bestand']['tmp_name'][$i], $map.$_FILES['bestand']['name'][$i])) {
$error = true;
}
}
}
?>
for($i = 0; $i < count($_FILES['bestand']['name']); $i++) {
if(IsSet($_FILES['bestand']['name'][$i]) && is_uploaded_file($_FILES['bestand']['tmp_name'][$i])) {
$sql = "INSERT INTO fotos (foto, project_id) VALUES ('".$_FILES['bestand']['name'][$i]."', '".$_POST['project_id']."')";
mysql_query($sql) or die (mysql_error());
if(!upload_file($_FILES['bestand']['tmp_name'][$i], $map.$_FILES['bestand']['name'][$i])) {
$error = true;
}
}
}
?>
k weet nie waar k dat neer moet gaan zetten (sorry)
Volgens mij zit dat er al in... in de if isset zit namelijk een is_uploaded_file, die dus goed moet zijn (ik weet alleen niet of is_uploaded net zoals move_uploaded_file een true or false teruggeeft.