PHP include error

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
RSmiroldo
Forum Newbie
Posts: 4
Joined: Tue Mar 11, 2008 9:22 pm

PHP include error

Post by RSmiroldo »

I'am trying to use this code <?php include("$id.txt"); ?> to generate content in the certain point in my layout so i can simply link to .txt files in the address bar so they appear in that portion of the layout but I'am currently getting the error Warning: main(.txt): failed to open stream: No such file or directory in /home/content/i/w/s/iwsports/html/index2.php on line 302 I'am so confused any suggestions?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: PHP include error

Post by Christopher »

Have you set your include_path somewhere to be "/home/content/i/w/s/iwsports/html/index2.php" instead of "/home/content/i/w/s/iwsports/html/" ?
(#10850)
RSmiroldo
Forum Newbie
Posts: 4
Joined: Tue Mar 11, 2008 9:22 pm

Re: PHP include error

Post by RSmiroldo »

no i dont think i have... not to sound stupid but how would i do that?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: PHP include error

Post by Christopher »

Well it's not finding the file on line 302 of you index.php. Where is the main.txt file? In the same directory as index.php? I should be if you haven't set anything else. Have you tried to include a file without using a variable to create the name? (e.g. just 'test.txt')
(#10850)
RSmiroldo
Forum Newbie
Posts: 4
Joined: Tue Mar 11, 2008 9:22 pm

Re: PHP include error

Post by RSmiroldo »

yes it is in the same directory as the index2.php thats why i dont understand why its not working...

since its in the same directory i assumed that the url would be
http://www.islandwidesports.com/index2.php?id=test and the test txt should display instead of the error.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: PHP include error

Post by Christopher »

It really should be something like:

Code: Select all

<?php include(preg_replace('/[^a-zA-Z0-9\_]/' , '', $_POST['id']) . '.txt'); ?>
(#10850)
RSmiroldo
Forum Newbie
Posts: 4
Joined: Tue Mar 11, 2008 9:22 pm

Re: PHP include error

Post by RSmiroldo »

when i tried putting that i got the same error.
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: PHP include error

Post by Zoxive »

RSmiroldo wrote:when i tried putting that i got the same error.
Probably because you haven't changed the include_path as stated earlier.

The include script above is just making it a bit more secure.
Post Reply