Check for Include Files in PHP


/ Published in: PHP
Save to your folder(s)

Simple way to check see if a file exists and is readable before you include it. Stops nasty error messages onscreen.


Copy this code and paste it in your HTML
  1. <?php
  2. $file = 'includes/filename.inc.php';
  3. if(file_exists($file) && is_readable($file)) {
  4. include($file);
  5. }
  6. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.