Jump to content

[SOLVED] require() reports fatal error, althought the file exists.


ZeroError

Recommended Posts

I'm pretty new to PHP, and am currently trying to build a very simple homepage which randomises a quote in the middle of the page, but also randomises the colours in the <body> tag.

I used a script from phpjunkyard.com to do the randomising and just require the scripts into the webpage.

 

I used this code for the body tag:

 

<body <?php require '/random/rand_bodycolour.php'; ?> >

 

and this code for the main quote:

 

<?php require '/random/rand_homebody.php'; ?>

 

and receive this error:

 

Warning: require(/random/rand_bodycolour.php) [function.require]: failed to open stream: No such file or directory in /home/user/public_html/index.php on line 10

 

Fatal error: require() [function.require]: Failed opening required '/random/rand_bodycolour.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/user/public_html/index.php on line 10

 

I had a brief problem when I moved the two files, which I fixed, but this error still occurs.

I must have checked it at least six times, and cannot see anything wrong with it.

 

Any ideas?

 

I did a brief Google search, and a quick search of your archives and couldn't find anything relating to my exact problem.

Link to comment
Share on other sites

Leading slashes / on file paths refer to the root of the current disk. I'll guess that the random folder is actually in your document root folder? If so, you should form a reference to the document root folder as follows -

 

require $_SERVER['DOCUMENT_ROOT'] . '/random/rand_bodycolour.php';

Link to comment
Share on other sites

Thank you, that seems to have worked. But now I get this error:

 

Warning: array_rand() [function.array-rand]: First argument has to be an array in /home/kittycat/public_html/random/rand_bodycolour.php on line 56

 

This is line 56 in the script:

54.     if (count($settings['quotes']))
55.     {
56.     	$txt = $settings['quotes'][array_rand($settings['quotes'])];
57.     }

Link to comment
Share on other sites

Ah, cr*p.

I've been a complete idiot and discounted the fact that the file (text_from_file), for whatever reason, could not be found. I used the solution given earlier for that, and it fixed both issues.

 

Sorry for wasting your time, and thank you for your help!

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.