Forum Moderators: coopster

Message Too Old, No Replies

Check if include exsists?

Want to supply error page if it doesn't.

         

Sypher_5

1:19 pm on Jan 14, 2004 (gmt 0)

10+ Year Member



I use this working code to switch the file I include.

$foo = "$d";// foo is equal to the d varible 
if($foo == "") {// if foo is equal to nothing
$dir ="_pages";// then $dir is _pages
}
else {// else
$dir = "$d";// $dir is equal to $d varible
}
$page = "$p.inc";// page is equal to the p varible
if($page == ".inc") {// if page is equal to nothing
$content = "home.inc";// then $content is $dir/homes.inc
$counter = "1";// & visitor counter is called
}
else {// else
$content = "$page";// $content is equal to $dir/$page varibles
}
// which means is the string is?d=_incl&p=page1
// then $content should be page1.inc in the _incl
// folder ( _incl/page1.inc )

Now I want to test that the include specified in the string exists, and if it doesn't that it includes an error page.

I've tried having a go with my novice skills but I'm getting parse errors.

if (is_file("$incl") {  
include($incl);
}
else {
include(_incl/error.inc);
}

Also tried using "file_exists" instead of "is_file".

On an added note is this going to cause much server slow down checking for the file?

I note that the pre and code tags here dont seem to work either..

[edited by: jatar_k at 4:19 pm (utc) on Jan. 14, 2004]
[edit reason] fixed sidescroll [/edit]

coopster

3:10 pm on Jan 14, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You are getting parse errors because you are missing a closing parenthesis. Try this:

if (is_file("$incl")) { // <-- note closing parenthesis!
include($incl);
} else {
include('_incl/error.inc');
}

Sypher_5

6:50 am on Jan 15, 2004 (gmt 0)

10+ Year Member



Thanks, should've know it was a syntax error.