Hulp Nodig bij het uploaden van meerdere bestanden in een database
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
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
<?php
//This is the directory where images will be saved
$target = "images/";
$target = $target . basename($_FILES['foto[]']['name']);
//This gets all the other information from the form
$street=$_POST['street'];
$type=$_POST['type'];
$foto1=($_FILES['foto']['name']);
$foto2=($_FILES['foto']['name']);
$foto3=($_FILES['foto']['name']);
$foto4=($_FILES['foto']['name']);
$foto5=($_FILES['foto']['name']);
// Connects to your Database
mysql_connect("localhost", "root", "root") or die(mysql_error()) ;
mysql_select_db("test") or die(mysql_error()) ;
//Writes the information to the database
mysql_query("INSERT INTO `test` VALUES ('$street', '$type', '$foto1','$foto2','$foto3','$foto4','$foto5')") ;
//Writes the photo to the server
if(move_uploaded_file($_FILES['foto']['tmp_name'], $target))
{
//Tells you if its all ok
echo "The files ". basename( $_FILES['foto']['name']). " has been uploaded, and your information has been added to the directory";
}
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>
//This is the directory where images will be saved
$target = "images/";
$target = $target . basename($_FILES['foto[]']['name']);
//This gets all the other information from the form
$street=$_POST['street'];
$type=$_POST['type'];
$foto1=($_FILES['foto']['name']);
$foto2=($_FILES['foto']['name']);
$foto3=($_FILES['foto']['name']);
$foto4=($_FILES['foto']['name']);
$foto5=($_FILES['foto']['name']);
// Connects to your Database
mysql_connect("localhost", "root", "root") or die(mysql_error()) ;
mysql_select_db("test") or die(mysql_error()) ;
//Writes the information to the database
mysql_query("INSERT INTO `test` VALUES ('$street', '$type', '$foto1','$foto2','$foto3','$foto4','$foto5')") ;
//Writes the photo to the server
if(move_uploaded_file($_FILES['foto']['tmp_name'], $target))
{
//Tells you if its all ok
echo "The files ". basename( $_FILES['foto']['name']). " has been uploaded, and your information has been added to the directory";
}
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>
doh! te snel gelezen
edit2:
je moet dmv een foreach al de $_FILES uitlezen...
Gewijzigd op 01/01/1970 01:00:00 door Crispijn -
Crispijn schreef op 27.01.2008 15:35:
edit:
doh! te snel gelezen
edit2:
je moet dmv een foreach al de $_FILES uitlezen...
doh! te snel gelezen
edit2:
je moet dmv een foreach al de $_FILES uitlezen...
Hehe? ik heb op de php site eens gekeken naar het uploaden van een array of files maar kom daar echtniet uit.
Zou je een voorbeeldje kunnen geven?
alvast bedankt
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
Oke bedankt maar hoe krijg ik de ingevoerde waarde in de database? in de database heb ik dus wel 5 verschillende foto velden waar de paths in komen?