php: require_once

Suspended
Joined
30 Jan 2005
Posts
467
Is there a way to change

<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/myfile.php');
?>

So if 'myfile.php' cannot be found it loads a error message instead of showing the fatal errors?
 
Try this...

Code:
<?
if(!@include_once($_SERVER['DOCUMENT_ROOT'].'/myfile.php'))
echo "Error, this file could not be included";
?>
 
How would I add a routine to this? Is it hard? Also, do you guys reccomend is_readable or file_exists?

<?php
$filename = 'test.txt';
if (is_readable($filename)) {
echo 'The file is readable';
} else {
echo 'The file is not readable';
}
?>
 
To throw another spanner in the works, remember that in some instances (I've only encountered it with safe_mode on) a file may not actually be readable despite is_readable() returning true.
 
You can use safe-mode-aware file_exists() to check it exists (as it returns false if a file can't be accessed due to safe mode restrictions) and then if it returns true use is_readable() to check you can read it.

I think that would work, anyway :)
 
Back
Top Bottom