user379888
user379888

Reputation:

Failed opening required file

I am getting the following error while running the code,

Warning: require_once(product.php) [function.require-once]: failed to open stream: No such file or directory in C:\xampp\htdocs\pro\application\modules\products\controllers\test1.php on line 2

Fatal error: require_once() [function.require]: Failed opening required 'product.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\pro\application\modules\products\controllers\test1.php on line 2

The code is simple,

<?php 
require_once "product.php";

    $array = "I am Fahad and I am testing this code";     
    $start = 4;
    $limit = 9;
    $value =  limit($array, $start, $limit);
    echo $value;
?>

The file product.php lies in the same directory as of the file which I am running. It still is giving an error. Please help out. Thanks

Upvotes: 3

Views: 23439

Answers (3)

Justin T.
Justin T.

Reputation: 3701

The actual current directory is not always the same than the script you are running, especially inside a framework like you seem to use right now.

To make sure this is working, use

require_once dirname(__FILE__) . '/product.php';

on 5.3, you can even say :

require_once __DIR__ . '/product.php';

Hope this helps !

Upvotes: 10

Adam Thornton
Adam Thornton

Reputation: 172

The error is simple, it can't find the file "product.php" in the place its currently looking.

Personally I would never trust the script to know where to look automatically, I would always try and give absolute paths. For example:

require_once $_SERVER['DOCUMENT_ROOT'] . '/somedir/anotherdir/product.php';

Upvotes: 0

Michael Seibt
Michael Seibt

Reputation: 1346

Check your filenames, especially case sensitivity (product.php != Product.php).

Upvotes: 1

Related Questions