foto's uit database tonen
Pagina: « vorige 1 2 3 volgende »
En wat als je foutafhandeling inbouwt op je if() van regel 28?en hoe bedoel je dat met die foutafhandeling.
Array
(
[files] => Array
(
[name] => Array
(
[0] => IMG_1063.JPG
[1] => IMG_1064.JPG
[2] => IMG_1068.JPG
[3] => IMG_1069.JPG
)
[type] => Array
(
[0] => image/jpeg
[1] => image/jpeg
[2] => image/jpeg
[3] => image/jpeg
)
[tmp_name] => Array
(
[0] => /public/tmp/phphQ5uTv
[1] => /public/tmp/phpqQRq0J
[2] => /public/tmp/phpq70Em3
[3] => /public/tmp/php4GSHRu
)
[error] => Array
(
[0] => 0
[1] => 0
[2] => 0
[3] => 0
)
=> Array
(
[0] => 2309592
[1] => 2305212
[2] => 3540365
[3] => 2729024
)
)
)
Controleer ook je pad eens?
Met het pad bedoel je denk ik het mapje waarnaar ik het upload ?
Die heb ik gecontroleerd en moet goed zijn met een ander upload script werkt dat ook prima.
Code (php)
1
2
3
4
5
6
7
2
3
4
5
6
7
<?php
if(move_uploaded_file($tmp_name,$location.$name)){
echo "move_uploaded_file gaf TRUE";
} else {
echo "move_uploaded_file gaf FALSE";
}
?>
if(move_uploaded_file($tmp_name,$location.$name)){
echo "move_uploaded_file gaf TRUE";
} else {
echo "move_uploaded_file gaf FALSE";
}
?>
Gewijzigd op 17/11/2014 16:15:33 door Frank Nietbelangrijk
Code (php)
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
<?php
if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], $path.$name))
{
echo "move_uploaded_file gaf TRUE";
} else {
echo "move_uploaded_file gaf FALSE";
}
?>
if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], $path.$name))
{
echo "move_uploaded_file gaf TRUE";
} else {
echo "move_uploaded_file gaf FALSE";
}
?>
Het resultaat is :
move_uploaded_file gaf TRUE
Wat geeft dit?
Code (php)
1
2
3
4
5
6
7
2
3
4
5
6
7
<?php
if(move_uploaded_file($tmp_name,$location.$name)){
echo "verplaatst naar: " . $location . $name;
} else {
echo "move_uploaded_file gaf FALSE";
}
?>
if(move_uploaded_file($tmp_name,$location.$name)){
echo "verplaatst naar: " . $location . $name;
} else {
echo "move_uploaded_file gaf FALSE";
}
?>
ik kan in het formulier meerdere foto's tegelijk selecteren om te uploaden maar hij upload er maar 1.
Ik sla $name op in de database "Bestandsnaam" en als ik de foto dan wil uitlezen. dan gebruik ik deze link. en krijg dan 1 foto te zien.
$foto = $row ["Bestandsnaam"];
'http://xxxxx.nl/Uploads/$foto'
deze regel heb ik nog eens toegevoegd
Gewijzigd op 17/11/2014 17:05:58 door Wouter van
Krijg je ook maar 1 keer "verplaatst naar: " te zien of krijg je dat meerdere keren te zien? Misschien nog even een keer je script posten zodat we nog eens kunnen kijken?
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
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
<?php
$name = ($_FILES["files"]["name"]);
$type = ($_FILES["files"]["type"]);
$size = ($_FILES["files"]["size"]);
$tmp_name = ($_FILES["files"]["tmp_name"]);
$valid_formats = array("jpg", "png", "gif", "zip", "bmp");
$max_file_size = 1024*200; //100 kb????????
$path = 'Uploads/'; // Upload directory
$count = 0;
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){
// Loop $_FILES to exeicute all files
foreach ($_FILES['files']['name'] as $f => $name) {
if ($_FILES['files']['error'][$f] == 4) {
continue; // Skip file if any error found
}
if ($_FILES['files']['error'][$f] == 0) {
if ($_FILES['files']['size'][$f] > $max_file_size) {
$message[] = "$name is too large!.";
continue; // Skip large files
}
elseif( ! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats) ){
$message[] = "$name is not a valid format";
continue; // Skip invalid file formats
}
else{ // No error found! Move uploaded files
if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], $path.$name))
$count++; // Number of successfully uploaded file
}
}
}
?>
<?php
if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], $path.$name))
?>
$name = ($_FILES["files"]["name"]);
$type = ($_FILES["files"]["type"]);
$size = ($_FILES["files"]["size"]);
$tmp_name = ($_FILES["files"]["tmp_name"]);
$valid_formats = array("jpg", "png", "gif", "zip", "bmp");
$max_file_size = 1024*200; //100 kb????????
$path = 'Uploads/'; // Upload directory
$count = 0;
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){
// Loop $_FILES to exeicute all files
foreach ($_FILES['files']['name'] as $f => $name) {
if ($_FILES['files']['error'][$f] == 4) {
continue; // Skip file if any error found
}
if ($_FILES['files']['error'][$f] == 0) {
if ($_FILES['files']['size'][$f] > $max_file_size) {
$message[] = "$name is too large!.";
continue; // Skip large files
}
elseif( ! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats) ){
$message[] = "$name is not a valid format";
continue; // Skip invalid file formats
}
else{ // No error found! Move uploaded files
if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], $path.$name))
$count++; // Number of successfully uploaded file
}
}
}
?>
<?php
if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], $path.$name))
?>
- Aar -:
Gelieve in het vervolg bij code de [code][/code]-tags gebruiken.
Hier kan je meer lezen over de mogelijke opmaakcodes.
Alvast bedankt!
Hier kan je meer lezen over de mogelijke opmaakcodes.
Alvast bedankt!
Toevoeging op 17/11/2014 17:18:22:
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
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
<?php
$name = ($_FILES["files"]["name"]);
$type = ($_FILES["files"]["type"]);
$size = ($_FILES["files"]["size"]);
$tmp_name = ($_FILES["files"]["tmp_name"]);
$valid_formats = array("jpg", "png", "gif", "zip", "bmp");
$max_file_size = 1024*200; //100 kb????????
$path = 'Uploads/'; // Upload directory
$count = 0;
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){
// Loop $_FILES to exeicute all files
foreach ($_FILES['files']['name'] as $f => $name) {
if ($_FILES['files']['error'][$f] == 4) {
continue; // Skip file if any error found
}
if ($_FILES['files']['error'][$f] == 0) {
if ($_FILES['files']['size'][$f] > $max_file_size) {
$message[] = "$name is too large!.";
continue; // Skip large files
}
elseif( ! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats) ){
$message[] = "$name is not a valid format";
continue; // Skip invalid file formats
}
else{ // No error found! Move uploaded files
if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], $path.$name))
$count++; // Number of successfully uploaded file
}
}
}
?>
$name = ($_FILES["files"]["name"]);
$type = ($_FILES["files"]["type"]);
$size = ($_FILES["files"]["size"]);
$tmp_name = ($_FILES["files"]["tmp_name"]);
$valid_formats = array("jpg", "png", "gif", "zip", "bmp");
$max_file_size = 1024*200; //100 kb????????
$path = 'Uploads/'; // Upload directory
$count = 0;
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){
// Loop $_FILES to exeicute all files
foreach ($_FILES['files']['name'] as $f => $name) {
if ($_FILES['files']['error'][$f] == 4) {
continue; // Skip file if any error found
}
if ($_FILES['files']['error'][$f] == 0) {
if ($_FILES['files']['size'][$f] > $max_file_size) {
$message[] = "$name is too large!.";
continue; // Skip large files
}
elseif( ! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats) ){
$message[] = "$name is not a valid format";
continue; // Skip invalid file formats
}
else{ // No error found! Move uploaded files
if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], $path.$name))
$count++; // Number of successfully uploaded file
}
}
}
?>
Gewijzigd op 17/11/2014 17:17:56 door - Ariën -
Let in onderstaand voorbeeld ook even op hoe het formulier is gemaakt!
Dit voorbeeldje werkt bij mij:
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
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
<?php
//$name = ($_FILES["files"]["name"]);
//$type = ($_FILES["files"]["type"]);
//$size = ($_FILES["files"]["size"]);
//$tmp_name = ($_FILES["files"]["tmp_name"]);
$valid_formats = array("jpg", "png", "gif", "zip", "bmp");
$max_file_size = 1024*200; //100 kb????????
$path = 'Uploads/'; // Upload directory
$count = 0;
if($_SERVER['REQUEST_METHOD'] == "POST")
{
// Loop $_FILES to execute all files
foreach ($_FILES['files']['name'] as $f => $name)
{
if ($_FILES['files']['error'][$f] == 4)
{
continue; // Skip file if any error found
}
if ($_FILES['files']['error'][$f] == 0)
{
if ($_FILES['files']['size'][$f] > $max_file_size)
{
echo "$name is too large!.";
continue; // Skip large files
}
elseif( ! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats) )
{
echo "$name is not a valid format";
continue; // Skip invalid file formats
}
else
{ // No error found! Move uploaded files
if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], $path.$name))
$count++; // Number of successfully uploaded file
}
}
}
}
?>
<form action="" method="post" enctype="multipart/form-data">
Send these files:<br />
<input name="files[]" type="file" /><br />
<input name="files[]" type="file" /><br />
<input name="files[]" type="file" /><br />
<input name="files[]" type="file" /><br />
<input type="submit" value="Send files" />
</form>
//$name = ($_FILES["files"]["name"]);
//$type = ($_FILES["files"]["type"]);
//$size = ($_FILES["files"]["size"]);
//$tmp_name = ($_FILES["files"]["tmp_name"]);
$valid_formats = array("jpg", "png", "gif", "zip", "bmp");
$max_file_size = 1024*200; //100 kb????????
$path = 'Uploads/'; // Upload directory
$count = 0;
if($_SERVER['REQUEST_METHOD'] == "POST")
{
// Loop $_FILES to execute all files
foreach ($_FILES['files']['name'] as $f => $name)
{
if ($_FILES['files']['error'][$f] == 4)
{
continue; // Skip file if any error found
}
if ($_FILES['files']['error'][$f] == 0)
{
if ($_FILES['files']['size'][$f] > $max_file_size)
{
echo "$name is too large!.";
continue; // Skip large files
}
elseif( ! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats) )
{
echo "$name is not a valid format";
continue; // Skip invalid file formats
}
else
{ // No error found! Move uploaded files
if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], $path.$name))
$count++; // Number of successfully uploaded file
}
}
}
}
?>
<form action="" method="post" enctype="multipart/form-data">
Send these files:<br />
<input name="files[]" type="file" /><br />
<input name="files[]" type="file" /><br />
<input name="files[]" type="file" /><br />
<input name="files[]" type="file" /><br />
<input type="submit" value="Send files" />
</form>
Toevoeging op 17/11/2014 18:31:48:
zo kan het ook:
Code (php)
1
2
3
4
5
6
7
2
3
4
5
6
7
<?php
<form action="" method="post" enctype="multipart/form-data">
Send these files:<br />
<input name="files[]" type="file" multiple="multiple" />
<input type="submit" value="Send files" />
</form>
?>
<form action="" method="post" enctype="multipart/form-data">
Send these files:<br />
<input name="files[]" type="file" multiple="multiple" />
<input type="submit" value="Send files" />
</form>
?>
Gewijzigd op 17/11/2014 18:28:43 door Frank Nietbelangrijk
Ik upload nu 4 foto's tegelijk en dat gaat goed.
is er ook een manier om ze alle 4 dan weer tegelijk in de browser te tonen ?
Hoe zou je dat het beste kunnen doen ?
Vier <img src='filename.jpg' /> HTML-tags.
De browser zal de in de HTML genoemde <img /> tags in aparte requests downloaden.
Heb je deze pagina:
Dan zullen er twee requests gedaan worden.
De eerste haalt de HTML op
En de tweede haalt de foto foto.jpg op
Gewijzigd op 17/11/2014 19:56:33 door Frank Nietbelangrijk
echo "<td> <a href = '<img src='filename.jpg' /></a></td>";
Bijna... zet in de href de link naar de foto, en de imagetag zet je voor de </a>
echo "<td> <a href = '<img src= http://www.XXXXXX.nl/Uploads/$foto'>Bekijk</td></a>";
zo bedoel je ?
En als je de image linkbaar wilt maken:
Code (php)
1
2
3
2
3
<?php
echo "<td> <a href = 'http://www.XXXXXX.nl/fotoboek.php'><img src='http://www.XXXXXX.nl/Uploads/".$foto."' /></td></a>";
?>
echo "<td> <a href = 'http://www.XXXXXX.nl/fotoboek.php'><img src='http://www.XXXXXX.nl/Uploads/".$foto."' /></td></a>";
?>
Gewijzigd op 17/11/2014 20:37:28 door - Ariën -
Ik heb het nu zo en dit werkt prima. alleen vraag ik me nog af hoe je die hoogte een breedte kan instellen.
als ik namelijk na $foto width= "150" height = "150" doe dan werkt dat niet
Beter is CSS gebruiken.