Jump to content

isset problems *solved*


digitalgod

Recommended Posts

hey guys,

why does
[code=php:0]
if (isset($_FILES['file1'])) {
[/code]
always return true, so the if statement is always processed, even though my file field (file1) is empty??
It's just a basic form that pulls info from the db and let's a user modify that info. I just can't understand why is it that when I [code=php:0]echo isset($_FILES{'file1'])[/code] it returns 1 even though the field is empty....

any ideas?
Link to comment
https://forums.phpfreaks.com/topic/27260-isset-problems-solved/
Share on other sites

if the file input has no value, it does not mean the file input was not part of the form. isset() tells you only if the form input was part of the form or if GET was a member of the query string name value pairs! So you should check with...

[code]if ( is_upload_file ( $_FILES['file1'] ) )
{
// do stuff
}[/code]

Which tells you if you have a uploaded file. For POST and GET you would do it differently, depending on the style you like to use...

// one example

[code]if ( isset ( $_POST['foo'] ) && trim ( $_POST['foo'] ) != '' )
{
// do stuff
}[/code]


Link to comment
https://forums.phpfreaks.com/topic/27260-isset-problems-solved/#findComment-124730
Share on other sites

Yes that is correct.

However the isset function does not check the value of a variable. Instead checks for the existence of a variable.

Also the reason why your code was returning true is because the $_FILE variable is created automatically with or without the field the variable is associated with is empty or not.
Link to comment
https://forums.phpfreaks.com/topic/27260-isset-problems-solved/#findComment-125069
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.