Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

Opening a text file from a php file


Go to End


2 Posts   1404 Views

Avatar
r0ar

Community Member, 13 Posts

2 August 2008 at 2:45am

Ok, so I have a php file in the Code folder, it has a corresponding template etc..
from the php file I want to open and read a text file.
as in
$file = 'filename.txt';
$data = file($file) or die("Failed");

it can't seem to find the text file

help please!!!

Avatar
Sigurd

Forum Moderator, 628 Posts

2 August 2008 at 6:29am

You'll be looking in the wrong folder.

Use "echo getcwd();" to find where you're looking.
http://nz.php.net/manual/en/function.getcwd.php

Then put in the correct relative or absolute path to the file.