Jump to content

Require Once error


Matt_M

Recommended Posts

When I try to load my site, I get this error:

 

 

 

Warning: require_once(/php/Constants.php) [function.require-once]: failed to open stream: No such file or directory in /home/fhlinux201/c/carsearchuk.co.uk/user/htdocs/index.php on line 2

 

Fatal error: require_once() [function.require]: Failed opening required '/php/Constants.php' (include_path='.:/usr/share/pear/') in /home/fhlinux201/c/carsearchuk.co.uk/user/htdocs/index.php on line 2

 

Can anyone please offer some advice or solution to why this is appearing. Any help will be greatly appreciated.

Link to comment
Share on other sites

use the include("folder/page.php"); function..........

 

looks like to me you havent set the folder permissions to 777 or 0777

 

Thanks for the quick reply. Sorry I'm a bit new to PHP and stuff, please could you tell me how to change the folder permissions.

 

Thanks muchly.

Link to comment
Share on other sites

require_once is fine (and indeed more stable than include if the file is necessary).

 

Your path to the included file is most likely wrong. It *could* be your permissions, but I doubt it. In what folder is the file that is calling this require function? In what folder is the file it is calling?

Link to comment
Share on other sites

And what is the function?

 

This in the entire contents of the index.php file.

 

<?

    require_once($DOCUMENT_ROOT . "/php/Constants.php");

    require_once(PHP . "Cars.php");

    require_once(PHP . "Lookup.php");

    require_once(PHP . "Source.php");

    require_once(PHP . "CarsBlock.php");

    require_once(PHP . "NewsBlock.php");

    require_once(PHP . "Error.php");

 

$Cars = new Cars();  // N.B. Do list unsold Cars

$result = $Cars->getHotListList();

#ERR_LOG("index.php::" . '$result=' . $result);

if ($result)

{

$source = new Source("index._htm");

$contents = $source->getText();

$hotListBlock = new CarsBlock($contents);

$hotListBlock->parseHotListList($Cars);

$hotListBlock->substitute($contents);

// now do it again for the second block

$Cars->reset();

$hotListBlock = new CarsBlock($contents);

$hotListBlock->parseAllList($Cars);

$hotListBlock->substitute($contents);

// now do it again for the news block

$lookup = new Lookup();  // N.B. Do get value

$result = $lookup->getListOnName("news");

if ($result)

{

$block = new NewsBlock($contents);

$block->parseNews($lookup);

$block->substitute($contents);

}

print($contents);

}

else

print("Error $result");

?>

 

By function do you mean require_once?

 

I appreciate the help.

Link to comment
Share on other sites

Assuming /htdocs/ is at the same level as /php/, you need to change your require functions to look like this:

 

    require_once("../" . PHP . "Cars.php")

 

The reason for this is because your document is in htdocs. The two periods and the slash bring you up one level to the root document, and then PHP brings you into the folder /PHP/ where 'cars.php' is located.

Link to comment
Share on other sites

Do not start file paths with a / in  your PHP scripts. If you use a slash at the start of a file path, PHP will try to load the file from the root of the harddrive. A / at the start of file pathss on *nix based OS's represents the root.

Start your file paths with ./ instead. The dot will means current working directory. Or append the DOCUMENT_ROOT superglobal first as recommended by Matt_M

 

<?php

define('PHP', './php/');

// OR
define('PHP', $_SERVER['DOCUMENT_ROOT'] . '/php/');

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.