Jump to content

[SOLVED] include file to add HTML text


websiteguy

Recommended Posts

Hi,
Probably a simple question, but then I am a noobie. I added a couple of static html pages to a PHPBB2 forum site. I want to use a .txt file so the site admin, (no web or html knowledge), can occasionally modify and upload to the servor.
The news.txt file looks like this:

<h1>UBRS Raid December 17th</h1><br />
    <br />
    <br />
<h2>Slaughtering The Beast!</h2><br />
<img src="images/the-beast-opt.jpg" alt="The Beast" width="650" height="462" /><br />
    <br />
    <br />
<h2>Drakki Down!</h2><br />
<p><img src="images/General-Drakkisath-opt.jpg" alt="General Drakkisath" width="650" height="432" /></p><br />
<p>Wicked completed their first successful UBRS run. Congrats to everyone<br />involved. Great teamwork, great fun, and greater things lay ahead!</p><br />
    <br />
    <br />

I put an include file at the spot in the index.html page I wanted this to appear.

<?php
include(“news.txt”);
?>

I get nothing at all. Can someone tell me what I'm missing?
Thanks,
Websiteguy
Link to comment
Share on other sites

That could be a problem. I already have a index.php file. That would be the forum home page. I added a index.html page as the sites home page so it would go to that first, then I have a button link on index.html to index.php (forum).

I didn't understand mjdamato's question about veiwing the source of the output.
Thanks,
Websiteguy
Link to comment
Share on other sites

Well, yeah that could be a problem. Just curious: why didn't you install it in a folder?

You have some options:
[list][*]rename index.php to something else and change all the links
[*]move all the forum to a folder
[*]have a meta refresh on index.html[/list]

I cant think of anymore, too tired, sorry :P
Link to comment
Share on other sites

None of the options sound too good, but then maybe I don't completely understand. (Learning everyday!)
I installed this forum several months ago. Now the Home Page was requested. Moving the forum to a subfolder could be a nightmare. (Forum is installed at the root level of the domain).
I first considered a redirect, but didn't know how to make it conditional when coming from the home page to the forum. (Lesson learned - Plan ahead!)
I am currently learning PHP to write complete websites using PHP. Sounds like the ticket.
Thanks,
Websiteguy
Link to comment
Share on other sites

I did think about creating a home.php and doing a redirect from there to the index.html home page. Or try naming it home.html, but I tried just uploading the index.html page first and it worked.
Unless my Host can change the start page on just this domain, otherwise I have 5 domains on my account at the time.
Appreciate the help,
Websiteguy
Link to comment
Share on other sites

You could try to use .htaccess...

Open notepad, hit file->save as.
In the filename box type ".htaccess" (with the quotes!)
Put
[code]
DirectoryIndex default.php index.php home.php index.html home.html
[/code]
In the .htaccess file and then upload it to your web server.
Rename index.html to default.php and it will go to that page first, allowing you to keep index.php so you do not have to alter links, and it will make it go to default.php first (assuming your host allows you to do .htaccess).
Link to comment
Share on other sites

I did a DirectoryIndex in the .htaccess file and changed my index.html to home.php. All that worked perfectly. Now I'm getting errors from my include. I'm sure all the errors are related to a path problem, but I've been reading and searching the net and am really stuck. Could someone point me in the right direction? Here are the errors:

Warning: main(“newstxt”) [function.main]: failed to open stream: No such file or directory in /home/xcelwebw/public_html/thewickedguild/home.php on line 42

Warning: main(“newstxt”) [function.main]: failed to open stream: No such file or directory in /home/xcelwebw/public_html/thewickedguild/home.php on line 42

Warning: main() [function.include]: Failed opening '“newstxt”' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/xcelwebw/public_html/thewickedguild/home.php on line 42

This is my include:

<?php
include(“news.txt”);
?>

It's located in /thewickedguild folder.
Thanks
Link to comment
Share on other sites

Not sure I thoroughly understand, but as usual, I'll check it out on the net and the PHP book I've started. Just a noobie. I thought about using echo, but I saw other examples that worked with only the include statement.
Thanks for the quick response.
Link to comment
Share on other sites

I finally solved the problem, and I got this from the PHP Freaks basics tutorials. I used the $docroot with the dirname() function and the _FILE_ constant to find the correct path.
<?php
$docroot = dirname(__FILE__).'/';
require_once($docroot.'news.txt');
?>

Thanks again to all the people on the forum that helped me and to the great tutorials on the PHP Freaks site!!
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.