prevent hanging

Discussion in 'PHP' started by adithya, Aug 4, 2008.

  1. #1
    Hi

    I was just playing with php and found a problem

    consider this snippet....
    
    $filename = "C:\Program Files\EasyPHP1-8\www\of\example.html";
    $htmlcontent=file_get_contents($filename);
    
    Code (markup):
    It works fine but if the example.html file doesn't exist then the server will hang..
    i tried this in easy php in vista and was unable to recover from the hang..
    I just thought what if the file is executed from the real server :eek:

    So Any good ways to prevent this...?
     
    adithya, Aug 4, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    if (is_file($filename))
    {
        $htmlcontent=file_get_contents($filename);
    }
    else
    {
        echo 'File not found';
        exit();
    }
    
    PHP:
     
    nico_swd, Aug 4, 2008 IP