Web Analytics Made Easy -
StatCounter file_exists as negative - CodingForum


No announcement yet.

file_exists as negative

  • Filter
  • Time
  • Show
Clear All
new posts

  • file_exists as negative

    very quick one boys and girls. how can i write this within an if statement to reflect if it returns a negative results.

    have tried
    if (file_exists($pic_m) == '0') { ... }
    but it's still returning some TRUE values. have tried ="FALSE" also but can't seem to nail it.

    any help?

  • #2
    "FALSE" indicates a string in PHP. '0' also indicates a string.
    file_exists is extremely open. Since its only a boolean, this is the easiest way:
    PHP Code:
    if (!file_exists($pic_m))
    // do stuff

    Offhand, you can probably do the same check in what.... 10 or so different ways.
    If it was a resource like MySQL, you need to check for identical matches. PHP is datatype weak, so 0 == false, though 0 === false. Checking the api is the best way to determine this, things like mysql_num_rows will return false on error, but will return 0 if it has none. These ones require a if (false !== mysql_num_rows($qryRes)), since one is a failure and one is just no records.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)