![]() |
php include not opening .txt file
I'm inserting a simple, well-rated script from hotscripts to randomly display quotes which are stored in a .txt file. The .txt file is not being recognized by the php script. I think maybe there is more to the .txt file than just entering quotes onto the blank page, seperated by hitting [enter], but I'm not sure. Thanks for any help.
This is the extent of the php script: Code:
// The name of your quote fileIn order to make it work you first have to edit quotes.txt and put all the quotes you want displayed in it. Is there more to the .txt file than appears? |
Nope, nothing more. You're just assuming you have data to work with and the file is read properly.
PHP Code:
__DIR__ . '/quotes.txt'; instead. |
Thanks, This is what I changed, and it didn't work. I tried __FILE__ too.
$fp = fopen(__DIR__ . '/quotes.txt', "r"); Also, are you suggesting updated code for the original script? I'm afraid I've gotten in over my head on this, but I'd like to finish what I started. Thanks again. |
Yeah, you can give it a shot I didn't test it. Works alright in my head though :o
If you aren't learning about file handling or anything like that, then this can be done much easier: PHP Code:
It is IMO wise to always include or open files relative to "this" script. Since you can include "this" script in a different one with a different path, PHP takes its cwd as that of the executing script, not the inclusions. Using relatives from __DIR__ will always produce the correct paths. |
| All times are GMT +1. The time now is 07:43 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.