Banner Rotator | failed to open stream

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Maxwellink
Forum Newbie
Posts: 7
Joined: Mon Jul 26, 2010 11:22 pm

Banner Rotator | failed to open stream

Post 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
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Banner Rotator | failed to open stream

Post by VladSun »

<?php include("content_rotation.php");?>
Where those : came from?
There are 10 types of people in this world, those who understand binary and those who don't
Maxwellink
Forum Newbie
Posts: 7
Joined: Mon Jul 26, 2010 11:22 pm

Re: Banner Rotator | failed to open stream

Post 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.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Banner Rotator | failed to open stream

Post 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.
There are 10 types of people in this world, those who understand binary and those who don't
Maxwellink
Forum Newbie
Posts: 7
Joined: Mon Jul 26, 2010 11:22 pm

Re: Banner Rotator | failed to open stream

Post 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)]);
 }
?>
Maxwellink
Forum Newbie
Posts: 7
Joined: Mon Jul 26, 2010 11:22 pm

Re: Banner Rotator | failed to open stream

Post 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?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Banner Rotator | failed to open stream

Post by Benjamin »

You can include anything you want.
Maxwellink
Forum Newbie
Posts: 7
Joined: Mon Jul 26, 2010 11:22 pm

Re: Banner Rotator | failed to open stream

Post 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!
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Banner Rotator | failed to open stream

Post by Benjamin »

Peace :drunk:
Post Reply