PHP: $_FILES not working
a2jfreak
Houston, TX Member
[php]
HTML:
<input type="file" name="a" size="30" />
<input type="file" name="b" size="30" />
<input type="file" name="c" size="30" />
PHP:
echo "=======\$_POST variables=======<br>\n";
foreach ($_POST as $key => $value) {
echo "$key\t= $value<br>\n";
}
echo "<br><br>=======\$_FILES variables=======<br>\n";
foreach ($_FILES as $key => $value) {
echo "$key\t= $value<br>\n";
}
[/php]
prints:
Notice how the FILE input elements show up in $_POST and not $_FILES?
Any idea what's wrong? I know I must have something wrong (and probably something stupid) but I don't know what.
HTML:
<input type="file" name="a" size="30" />
<input type="file" name="b" size="30" />
<input type="file" name="c" size="30" />
PHP:
echo "=======\$_POST variables=======<br>\n";
foreach ($_POST as $key => $value) {
echo "$key\t= $value<br>\n";
}
echo "<br><br>=======\$_FILES variables=======<br>\n";
foreach ($_FILES as $key => $value) {
echo "$key\t= $value<br>\n";
}
[/php]
prints:
=======$_POST variables=======
a = abc.jpg
b = xyz.jpg
c = 123.jpg
=======$_FILES variables=======
Notice how the FILE input elements show up in $_POST and not $_FILES?
Any idea what's wrong? I know I must have something wrong (and probably something stupid) but I don't know what.
0
Comments
Next, for displaying the results, because $_FILES is multidimensional, you're going to need a foreach in your foreach:
[php]
echo "=======\$_FILES variables=======\n";
foreach ($_FILES as $key => $value) {
foreach ($value as $value2) {
echo "$key\t= $value2\n<br />";
}
}[/php]
The problem is that it's going to display each value of the array. I'm not sure how to display just the filename.
[php]
$attachment = $_FILES[$file];
$attachment_name = $_FILES[$file];
[/php]
The enctype is what was wrong . . . thanks!