PHP include error
Moderator: General Moderators
PHP include error
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?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: PHP include error
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)
Re: PHP include error
no i dont think i have... not to sound stupid but how would i do that?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: PHP include error
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)
Re: PHP include error
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.
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.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: PHP include error
It really should be something like:
Code: Select all
<?php include(preg_replace('/[^a-zA-Z0-9\_]/' , '', $_POST['id']) . '.txt'); ?>(#10850)
Re: PHP include error
when i tried putting that i got the same error.
Re: PHP include error
Probably because you haven't changed the include_path as stated earlier.RSmiroldo wrote:when i tried putting that i got the same error.
The include script above is just making it a bit more secure.