Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Catching file not found warnings 2

Status
Not open for further replies.

gregmosu

Programmer
Joined
Jul 8, 2002
Messages
117
Location
US
Hello all,

I keep getting an warning message printed to the screen when a file cant be opened..

$fp = file("/path/myfile.txt");

Is there a dienice or croak function in php that will catch the error message so the user doesnt have to see it?

Thanks,
Greg
 
You can use the @ sign:
Code:
$fp = @file("/path/myfile.txt");

However, you will still end up with a 'bad' filepointer that will fail on the next file command.
It is preferable to handle the possible 'not found' error explicitly rather than choking the warnings that PHP produces.

My recommendation:
Use is_file() and is_dir() to check for existence rather than having the file commands fail.
 
so use is_file() to check for the existence of it before trying to open it.

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top