I’m doing some tests with forms and ran into a snag, I have a very simple test script that works, but the problem is that my FILE field in the form is not getting submitted to the $_POST array for some reason, if I take out encode=”multipart/form-data” it does, otherwise I just get the other fields. Here is the script:
<?PHP
print_r($_POST);
echo"<br>";
print_r($_FILES);
$name = $_FILES["img1"]["name"];
$tmp_name = $_FILES["img1"]["tmp_name"];
$uploads_dir = "uploads";
echo "<br>TEMP NAME:</b>";
echo $tmp_name;
move_uploaded_file($tmp_name, "$uploads_dir/$name");
?>
<html>
<body>
<br><br>
-------------------------
<form name="test" id="test" action="index.php" method="post" enctype="multipart/form-data">
<label>Name</label>
<input type="text" name="title" id="title">
<br>
<label>File</label>
<input type="file" name="img1" id="img1" size="40">
<br>
<input type="submit" value="submit">
</form>
The output is:
POST ARRAY: Array ( [title] => some title )
FIELS ARRAY: Array ( [img1] => Array ( [name] => chicken.jpg [type] => image/jpeg [tmp_name] => /tmp/phpcrBLw9 [error] => 0 [size] => 30940 ) )
TEMP NAME:/tmp/phpcrBLw9
As you can see, the POST only has the title, not the file name, I need it to have both for programming reasons, is there a way to do that without having to cheat / have hidden fields or edited values manually?
You will not be able to see $_FILES inside $_POST. They are different superglobals, if you
vardump($_FILES);you will see that it stores all the information about the uploaded file, like size, tmp name etc. This is how PHP has been built, and the only thing you can do about it is access the name using