Page 1 of 1

PHP include error

Posted: Tue Mar 11, 2008 9:23 pm
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?

Re: PHP include error

Posted: Tue Mar 11, 2008 9:58 pm
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/" ?

Re: PHP include error

Posted: Tue Mar 11, 2008 10:00 pm
by RSmiroldo
no i dont think i have... not to sound stupid but how would i do that?

Re: PHP include error

Posted: Tue Mar 11, 2008 10:27 pm
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')

Re: PHP include error

Posted: Tue Mar 11, 2008 10:30 pm
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.

Re: PHP include error

Posted: Wed Mar 12, 2008 12:30 am
by Christopher
It really should be something like:

Code: Select all

<?php include(preg_replace('/[^a-zA-Z0-9\_]/' , '', $_POST['id']) . '.txt'); ?>

Re: PHP include error

Posted: Wed Mar 12, 2008 8:31 am
by RSmiroldo
when i tried putting that i got the same error.

Re: PHP include error

Posted: Wed Mar 12, 2008 10:20 am
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.