Include fail safe

Discussion in 'PHP' started by Raynor152, Mar 20, 2008.

  1. #1
    I implemented a simple php scrpit that shows a random line of text on my webpage from the file qsdatabase.php.

    <?php
    $quotes = file("random/qsdatabase.php");
    $quote = rand(0, sizeof($quotes)-1);
    echo $quotes[$quote];
    ?>

    From time to time it gives a error it can't find the file qsdatabase.php on the server. And it displays that message on the screen which I just can't have :p I'm kind of new to php. Can someone please show me how to make a fail safe or something. Like if it does not find the file to display another pre-set message or just don't display anyhing.
     
    Raynor152, Mar 20, 2008 IP
  2. djliku

    djliku Peon

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think you can use this

    if(file_exists('random/qsdababase.php')!=FALSE) {
    	$quotes = file("random/qsdatabase.php");
    	$quote = rand(0, sizeof($quotes)-1);
    	echo $quotes[$quote];
    }
    PHP:
     
    djliku, Mar 20, 2008 IP