index.php passes firstName and an image to save.php via post.
Save.php is checking $_POST
and $_FILES
to be not empty via isset method.
when nothing is sent by POST it should give an error and dies but inside of if block never runs and if we print the array there is nothing in it. which means that nothing passed via $_POST
or $_FILES
.
when firstName and image are passed it works fine, but when nothing passed isset doesn't recognize it.why?
'error' field of $_FILES
array has error code 4, which means 'No file was uploaded', in this case also if block should be execute but doesn't.
this is index.php
<form action="save.php" method="post" enctype="multipart/form-data">
name: <input type="text" name="firstName"><br>
pic: <input type="file" name="pic"><br>
<input type="submit" value="register">
</form>
and here is the save.php:
<?php
if (!isset($_POST['firstName']) || !isset($_FILES['pic']))
{
die('input error');
}
echo '<pre>';
print_r($_POST);
print_r($_FILES);
echo '</pre>';
output:
Array
(
[firstName] =>
)
Array
(
[pic] => Array
(
[name] =>
[full_path] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)
)