Page 1 of 1

Banner Rotator | failed to open stream

Posted: Mon Jul 26, 2010 11:55 pm
by Maxwellink
I'm trying to build a simple php snippet that will switch the main banner every time the home page is loaded/refreshed. I'm using the 'include' function to link to the external php file with the code.

I am receiving this error message:

Warning: include(.:content_rotation.php) [function.include]: failed to open stream: No such file or directory in /home2/incomeq0/public_html/maxwellink/index.php on line 58

Warning: include() [function.include]: Failed opening '.:content_rotation.php' for inclusion (include_path='.:/usr/lib64/php:/usr/lib/php') in /home2/incomeq0/public_html/maxwellink/index.php on line 58


website:http://www.maxwellink.net

Here is the PHP I have in my index.php file:

Code: Select all

<?php	
$content_rotation_list = array(
  ".:hm_bn_1.html",
  ".:hm_bn_2.html"
 );
?>

//v v v v v This is Line 58 v v v v v	
<?php include(".:content_rotation.php");?>
Both the HTML files and PHP files are located in the root folder.

Here is the PHP in the file "content_rotation.php":

Code: Select all

<?php
	if (isset($content_rotation_list)
	&& is_array($content_rotation_list)
	&& count($content_rotation_list) > 0) {
		srand(time());
		include($content_rotation_list[rand(0,count($content_rotation_list)-1)]);
	}
?>
I have set the permissions of the content_rotation.php and index.php to 700. I read that in a similar post.



I'm pulling my hair out over here...I need a beer :drunk:

Thanks for the help

~z

Re: Banner Rotator | failed to open stream

Posted: Tue Jul 27, 2010 1:23 am
by VladSun
<?php include("content_rotation.php");?>
Where those : came from?

Re: Banner Rotator | failed to open stream

Posted: Tue Jul 27, 2010 8:49 am
by Maxwellink
I read and seen on forums where people were putting ".:" in front of the file name to tell the code to look in the current folder. I did change it to just ".content_rotation.php" but that didn't change the error. I cannot find anything wrong. Everything is in the right place in the directories.

Re: Banner Rotator | failed to open stream

Posted: Tue Jul 27, 2010 9:05 am
by VladSun
Current folder is ./
I.e. you need ./content.php, though if you don't specify a path it will be looked up in the current directory first.

Re: Banner Rotator | failed to open stream

Posted: Tue Jul 27, 2010 9:22 am
by Maxwellink
VladSun

I switched the code to your suggestion. But now I'm getting the same error message, but on a different line:

Warning: include(hm_bn_2.html) [function.include]: failed to open stream: No such file or directory in /home2/incomeq0/public_html/maxwellink/content_rotation.php on line 8

Warning: include() [function.include]: Failed opening 'hm_bn_2.html' for inclusion (include_path='.:/usr/lib64/php:/usr/lib/php') in /home2/incomeq0/public_html/maxwellink/content_rotation.php on line 8


I tried adding "./" before both html files with no success, I still get the error.

Code: Select all

<?php
	if (isset($content_rotation_list)
 && is_array($content_rotation_list)
 && count($content_rotation_list) > 0) {
  srand(time());
  
  include($content_rotation_list[
//v v v v v v THIS IS LINE 8 v v v v v v
   rand(0,count($content_rotation_list)-1)]);
 }
?>

Re: Banner Rotator | failed to open stream

Posted: Tue Jul 27, 2010 9:49 am
by Maxwellink
I figured it out. I converted my html files to .php and it worked.

So my last question:

can the include/require() function only call .php files?

Re: Banner Rotator | failed to open stream

Posted: Tue Jul 27, 2010 9:49 am
by Benjamin
You can include anything you want.

Re: Banner Rotator | failed to open stream

Posted: Tue Jul 27, 2010 10:14 am
by Maxwellink
Benjamin wrote:You can include anything you want.
You're right, because my header and footer are called using the same method, and they're .htm files.

I realize now I think it was because I was naming my file: hm_bn_1.html. When I remove the underscores it all seems to fall into place.

Thanks for the time fellas!

Re: Banner Rotator | failed to open stream

Posted: Tue Jul 27, 2010 10:15 am
by Benjamin
Peace :drunk: