Poll

Helpful?

Yes
0 (0%)
No (Post why)
0 (0%)

Total Members Voted: 0

Voting closed: December 30, 2007, 01:27:53 AM

Author Topic: Fail safe includes and requires  (Read 2473 times)

Acecool

  • Regular Member
  • **
  • Posts: 73
  • Karma: +0/-0
    • View Profile
    • PHP programmers forum
Fail safe includes and requires
« on: December 04, 2007, 08:46:41 PM »
http://http://www.acecoolco.com/tutorials/3/fail-safe-includes-and-requires/page_1/tutorial_24.html

This tutorial shows you how to use a built in php check to safely remove errors


Code added for ease of use:

This check checks that a file exists before including it.
PHP Code Box

PHP Code: [Select]

<?php
if (file_exists("./path/to/file.php"))
{
    include(
"./path/to/file.php");
}
?>



This check checks that a file exists before requiring it.
PHP Code Box

PHP Code: [Select]

<?php
if (file_exists("./path/to/file.php"))
{
    require(
"./path/to/file.php");
}
?>



If you wanted to add an error message to these, simply add an else statement.
PHP Code Box

PHP Code: [Select]
	

<?
php
if (file_exists("./path/to/file.php"))
{
    require(
"./path/to/file.php");
}
else
{
    echo 
"./path/to/file.php File was not included / required.";
}
?>