file_exists bug?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Bob Kellock
Forum Newbie
Posts: 10
Joined: Fri Oct 30, 2009 10:57 am
Location: Wiltshire, UK

file_exists bug?

Post by Bob Kellock »

$recfile = $_GET[r];
if (file_exists('CustDat/' . $recfile))
{...............

Normally works correctly but if $_GET[r] returns a null then file_exists returns True.

Seems a bit odd to me

Bob
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: file_exists bug?

Post by AbraCadaver »

Bob Kellock wrote:$recfile = $_GET[r];
if (file_exists('CustDat/' . $recfile))
{...............

Normally works correctly but if $_GET[r] returns a null then file_exists returns True.

Seems a bit odd to me

Bob
If $recfile is empty then you are checking the dir 'CustDat/' which is a file and I assume does exist :D

Try is_file() or work on your program logic so that you don't do the check if the var is empty (makes more sense). Your code is sloppy.

-Shawn
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply