[NooB] Fout in werkende code
Notice: Use of undefined constant x - assumed 'x' in C:\Program Files\Apache Group\Apache2\htdocs\test\upload.php on line 32
Notice: Undefined index: x in C:\Program Files\Apache Group\Apache2\htdocs\test\upload.php on line 32
Notice: Use of undefined constant accept - assumed 'accept' in C:\Program Files\Apache Group\Apache2\htdocs\test\upload.php on line 46
Het script ziet er als volgt uit:
Code (php)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<title>SPeedY_B - File Upload</title>
<link rev="made" href="mailto:admin at speedyb co uk" />
<meta name="keywords" content="SPeedY_B, speedy, b, dave, php, html" />
<meta name="description" content="SPeedY_B - File Upload" />
<meta name="author" content="David G Kerry" />
<meta name="robots" content="ALL" />
<meta name="copyright" content="David G Kerry" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body {
font-family: verdana, arial, sans-serif;
font-size : 12px;
color: #000000;
background-color: #FFFFFF;
}
</style>
</head>
<body>
<div>
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
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
<?php
switch($_GET[x]) {
default:
print "Upload a file (Max $limit bytes)
<br /> <br />
<form action=\"?x=accept\" method=\"post\" enctype=\"multipart/form-data\">
<div>
<input type=\"file\" size=\"60\" name=\"filename\" />
<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$limit\" />
<input type=\"submit\" value=\"upload\" />
</div>
</form>";
break;
case accept:
if (file_exists($file . $_FILES['filename']['name'])) {
print "Sorry, A file with this name already exists, please re-name the file and try again.<br /><br />[<a href=\"./\">back</a>]";
} else {
if ($_FILES['filename']['size'] >= $limit) {
print "File size too large<br /><br />[<a href=\"./\">back</a>]";
} else {
move_uploaded_file($_FILES['filename']['tmp_name'], $file . $_FILES['filename']['name']);
print "File Uploaded!, check [<a href=http://frankie.sytes.net/test/uploaded>all uploaded files here!</a>]!";
}
}
break;
}
?>
switch($_GET[x]) {
default:
print "Upload a file (Max $limit bytes)
<br /> <br />
<form action=\"?x=accept\" method=\"post\" enctype=\"multipart/form-data\">
<div>
<input type=\"file\" size=\"60\" name=\"filename\" />
<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$limit\" />
<input type=\"submit\" value=\"upload\" />
</div>
</form>";
break;
case accept:
if (file_exists($file . $_FILES['filename']['name'])) {
print "Sorry, A file with this name already exists, please re-name the file and try again.<br /><br />[<a href=\"./\">back</a>]";
} else {
if ($_FILES['filename']['size'] >= $limit) {
print "File size too large<br /><br />[<a href=\"./\">back</a>]";
} else {
move_uploaded_file($_FILES['filename']['tmp_name'], $file . $_FILES['filename']['name']);
print "File Uploaded!, check [<a href=http://frankie.sytes.net/test/uploaded>all uploaded files here!</a>]!";
}
}
break;
}
?>
</div>
</body>
</html>
De fout zit geloof ik in "switch($_GET[x]) ". Ik weet alleen niet wat dit "switch"doet, en waarom het uberhaupt in het script staat, het simpel verwijderen van deze regel laat het script igg helemaal niet werken.
Ik hoop dat er iemand is die weet wat er mis is.
Zet ' ' om de x heen dan werkt het als het goed is
en ook om accept op lijn 46
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\Program Files\Apache Group\Apache2\htdocs\test\upload.php on line 32
Het stuk code is nu zo:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
<?php
switch($_GET"x") {
default:
print "Upload a file (Max $limit bytes)
<br /> <br />
<form action=\"?x="accept"\" method=\"post\" enctype=\"multipart/form-data\">
<div>
<input type=\"file\" size=\"60\" name=\"filename\" />
<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$limit\" />
<input type=\"submit\" value=\"upload\" />
</div>
......
?>
switch($_GET"x") {
default:
print "Upload a file (Max $limit bytes)
<br /> <br />
<form action=\"?x="accept"\" method=\"post\" enctype=\"multipart/form-data\">
<div>
<input type=\"file\" size=\"60\" name=\"filename\" />
<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$limit\" />
<input type=\"submit\" value=\"upload\" />
</div>
......
?>
Ik heb het ook met enkele aanhalingstekens geprobeerd, maar dat maakte geen verschil.
Gewijzigd op 18/08/2004 16:32:00 door XXfrankieXX
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
<?php
switch($_GET["x"]) {
default:
print "Upload a file (Max $limit bytes)
<br /> <br />
<form action=\"?x=accept\" method=\"post\" enctype=\"multipart/form-data\">
<div>
<input type=\"file\" size=\"60\" name=\"filename\" />
<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"". $limit ."\" />
<input type=\"submit\" value=\"upload\" />
</div>
......
?>
switch($_GET["x"]) {
default:
print "Upload a file (Max $limit bytes)
<br /> <br />
<form action=\"?x=accept\" method=\"post\" enctype=\"multipart/form-data\">
<div>
<input type=\"file\" size=\"60\" name=\"filename\" />
<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"". $limit ."\" />
<input type=\"submit\" value=\"upload\" />
</div>
......
?>
Zo moet die werken volgens mij
Notice: Undefined index: x in C:\Program Files\Apache Group\Apache2\htdocs\test\upload.php on line 32
Notice: Use of undefined constant accept - assumed 'accept' in C:\Program Files\Apache Group\Apache2\htdocs\test\upload.php on line 46
Ik heb deze error met meer scripts, misschien is het een verkeerde instelling in php (PHP Version 4.3.6)