Grote van afbeelding controleren.
Nadat een uploadscript goed werkt, wil ik dat er gecontroleerd wordt op de grote van de foto. Onderstaand staat de code toe nu toe. Volgens mij staat alles er nu in, maar hij upload nog steeds iedere grote.
Wat zit er verkeerd?
Alvast bedankt,
Code:
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
127
128
129
130
131
132
133
134
135
136
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
127
128
129
130
131
132
133
134
135
136
<?php
include ('connect.php');
/**************** Configuratie *****************/
$file_mimes = array('image/jpeg','image/jpg'); // Toegestane bestand Mime Types. Voeg zonodig meer mime types toe.
$file_exts = array('.jpg', '.gif', '.bmp'); // Toegestane bestand extensies. Voeg zonodig meer mime-types toe.
$upload_dir = "foto/"; // Map waar alle uploads opgeslagen worden. (eindigend op "/")
$aantal_u = "1"; // Aantal mogelijke uploads per keer
$up_empty = "Leeg"; // Boodschap bij leeg uploadveld.
$up_finish = "Je foto is succesvol toegevoegd aan de database."; // Boodschap bij Geslaagde upload.
$up_fail = "Mislukt"; // Boodschap bij mislukte upload.
$up_perm = "Veranderen van de permissies naar 777 is mislukt"; // Boodschap bij mislukken van veranderen permissies
?>
<html>
<head>
<title>Uploaden foto's</title>
</head>
<body>
<center>
<?PHP
$url_dir = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
$url_this = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$upload_url = $url_dir."/".$upload_dir."/";
if($_REQUEST[upload])
{
/************* Maak Upload Map *****************/
if (!is_dir("$upload_dir"))
{
if (!mkdir($upload_dir))
die ($upload_dir."map bestaat niet en het aanmaken is mislukt.");
if (!chmod($upload_dir,0777))
die ($upload_dir.", ".$up_perm.".");
}
/********** Begin Controle En Upload **************/
for($x = 0; $x < $aantal_u; $x++)
{
$upfile = 'upfile_'.$x;
$file_name = $_FILES[$upfile]['name'];
$file_type = $_FILES[$upfile]['type'];
$file_ext = strtolower(substr($file_name,strrpos($file_name,".")));
echo "<b>Upload ".($x+1).":</b> ";
if ($file_name != "" && $file_type != "")
{
if (!in_array($file_type, $file_mimes) && !in_array($file_ext, $file_exts))
{
echo "<b><font color=\"FF0000\">".$up_fail."</font></b><br>\n";
}
else
{
$temp_name = $_FILES[$upfile]['tmp_name'];
$file_name = $_FILES[$upfile]['name'];
$file_name = str_replace("\\","",$file_name);
$file_name = str_replace("'","",$file_name);
$file_path = $upload_dir.$file_name;
if($_FILES['userfile']['size']>80000) {
echo "foto is groter dan 80 kb";
}else{
}
include ('connect.php');
$ip = $_SERVER['REMOTE_ADDR'];
$sql = "SELECT * FROM vakantiefotos WHERE foto = '$file_name'";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) == 0)
{
$query="INSERT INTO vakantiefotos (foto,ip,actief)";
$query=$query. "VALUES ('";
$query=$query . $file_name."','";
$query=$query . $_POST["ip"]."','";
$query=$query . $_POST["actief"]."');";
$result=mysql_query($query) or die ("FOUT: ".mysql_error());
//echo ("De query is als volgt: <b>$query</b><hr>");
$result = move_uploaded_file($temp_name, $file_path);
if($result)
{
echo "<BR><BR><b><font color=red>".$up_finish."</font></b><br><BR><BR>";
}
else
{
echo "<b><font color=\"FF0000\"><BR><BR>".$up_fail."</font></b><br>";
}
}
else
{
echo "<b><font color=\"FF0000\"><BR><BR>Foto is al een keer geupload.<BR><BR></font>";
}
}
}
else echo "<i>$up_empty</i><br>\n";
}
}
?>
<form name="upload" method="post" action="uploadfoto.php" enctype="multipart/form-data">
<?PHP
for ($i = 0; $i < $aantal_u; $i++)
{
echo " <TR><TD bgColor=98cb00><B>Foto:</B></TD><TD bgColor=98cb00><input type=\"file\" size=84 class=formulier1 name=\"upfile_".$i."\"><br>\n";
}
$ip = $_SERVER['REMOTE_ADDR'];
echo ("<TR><TD colspan=2 bgColor=98cb00></TD><input type=hidden value=$ip name=ip size=20></TD></TR>");
?>
<TR><TD colspan=2 bgColor=98cb00><input type=hidden value=ja name=actief size=20></TD></TR>
<TR><TD colspan=2 bgColor=98cb00><input type="submit" name="upload" class=formulier1 value="Upload" size="83"> </TR></TD>
</form>
<TR><TD colspan=2 bgColor=98cb00 height=400> </TD></TR>
<?php
include ('include/footer.php');
?>
</SPAN></B></TD></TR></FONT></TBODY></table>
include ('connect.php');
/**************** Configuratie *****************/
$file_mimes = array('image/jpeg','image/jpg'); // Toegestane bestand Mime Types. Voeg zonodig meer mime types toe.
$file_exts = array('.jpg', '.gif', '.bmp'); // Toegestane bestand extensies. Voeg zonodig meer mime-types toe.
$upload_dir = "foto/"; // Map waar alle uploads opgeslagen worden. (eindigend op "/")
$aantal_u = "1"; // Aantal mogelijke uploads per keer
$up_empty = "Leeg"; // Boodschap bij leeg uploadveld.
$up_finish = "Je foto is succesvol toegevoegd aan de database."; // Boodschap bij Geslaagde upload.
$up_fail = "Mislukt"; // Boodschap bij mislukte upload.
$up_perm = "Veranderen van de permissies naar 777 is mislukt"; // Boodschap bij mislukken van veranderen permissies
?>
<html>
<head>
<title>Uploaden foto's</title>
</head>
<body>
<center>
<?PHP
$url_dir = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
$url_this = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$upload_url = $url_dir."/".$upload_dir."/";
if($_REQUEST[upload])
{
/************* Maak Upload Map *****************/
if (!is_dir("$upload_dir"))
{
if (!mkdir($upload_dir))
die ($upload_dir."map bestaat niet en het aanmaken is mislukt.");
if (!chmod($upload_dir,0777))
die ($upload_dir.", ".$up_perm.".");
}
/********** Begin Controle En Upload **************/
for($x = 0; $x < $aantal_u; $x++)
{
$upfile = 'upfile_'.$x;
$file_name = $_FILES[$upfile]['name'];
$file_type = $_FILES[$upfile]['type'];
$file_ext = strtolower(substr($file_name,strrpos($file_name,".")));
echo "<b>Upload ".($x+1).":</b> ";
if ($file_name != "" && $file_type != "")
{
if (!in_array($file_type, $file_mimes) && !in_array($file_ext, $file_exts))
{
echo "<b><font color=\"FF0000\">".$up_fail."</font></b><br>\n";
}
else
{
$temp_name = $_FILES[$upfile]['tmp_name'];
$file_name = $_FILES[$upfile]['name'];
$file_name = str_replace("\\","",$file_name);
$file_name = str_replace("'","",$file_name);
$file_path = $upload_dir.$file_name;
if($_FILES['userfile']['size']>80000) {
echo "foto is groter dan 80 kb";
}else{
}
include ('connect.php');
$ip = $_SERVER['REMOTE_ADDR'];
$sql = "SELECT * FROM vakantiefotos WHERE foto = '$file_name'";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) == 0)
{
$query="INSERT INTO vakantiefotos (foto,ip,actief)";
$query=$query. "VALUES ('";
$query=$query . $file_name."','";
$query=$query . $_POST["ip"]."','";
$query=$query . $_POST["actief"]."');";
$result=mysql_query($query) or die ("FOUT: ".mysql_error());
//echo ("De query is als volgt: <b>$query</b><hr>");
$result = move_uploaded_file($temp_name, $file_path);
if($result)
{
echo "<BR><BR><b><font color=red>".$up_finish."</font></b><br><BR><BR>";
}
else
{
echo "<b><font color=\"FF0000\"><BR><BR>".$up_fail."</font></b><br>";
}
}
else
{
echo "<b><font color=\"FF0000\"><BR><BR>Foto is al een keer geupload.<BR><BR></font>";
}
}
}
else echo "<i>$up_empty</i><br>\n";
}
}
?>
<form name="upload" method="post" action="uploadfoto.php" enctype="multipart/form-data">
<?PHP
for ($i = 0; $i < $aantal_u; $i++)
{
echo " <TR><TD bgColor=98cb00><B>Foto:</B></TD><TD bgColor=98cb00><input type=\"file\" size=84 class=formulier1 name=\"upfile_".$i."\"><br>\n";
}
$ip = $_SERVER['REMOTE_ADDR'];
echo ("<TR><TD colspan=2 bgColor=98cb00></TD><input type=hidden value=$ip name=ip size=20></TD></TR>");
?>
<TR><TD colspan=2 bgColor=98cb00><input type=hidden value=ja name=actief size=20></TD></TR>
<TR><TD colspan=2 bgColor=98cb00><input type="submit" name="upload" class=formulier1 value="Upload" size="83"> </TR></TD>
</form>
<TR><TD colspan=2 bgColor=98cb00 height=400> </TD></TR>
<?php
include ('include/footer.php');
?>
</SPAN></B></TD></TR></FONT></TBODY></table>
Gewijzigd op 01/01/1970 01:00:00 door Martijn
werkt prima zo.. weet je zeker dat je fotos groter zijn?
ja, 100% zeker