Thursday, 8 August 2013

php if file exists include file if not include another file

php if file exists include file if not include another file

I am trying to include a file if it exists, if the file doesn't exist i
would like it to include another file instead.
I have the following code which seems to work correctly, The only problem
with my code is if the file does exist then it displays them both.
I would like to only include
include/article.php
if
include/'.$future.'.php
doesn't exist.
if
include/'.$future.'.php
exists i don't want to include
include/article.php
<?php
$page = $_GET['include'];
if (file_exists('include/'.$future.'.php')){
include('include/'.$future.'.php');
}
else{
include('include/article.php');
}
?>

No comments:

Post a Comment