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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Fetch Data from Text File


Go to End


3 Posts   1212 Views

Avatar
akshu

Community Member, 7 Posts

27 May 2010 at 5:48pm

hello everyone,

i'm trying following code to show data from text file to user....

$myFile = "testing.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
return $theData;

but it s showing error "no such file or directory" ... Is it the right way ?? or please tell me how to do it...

Avatar
akshu

Community Member, 7 Posts

27 May 2010 at 6:29pm

get it working... just need to give the full path of file

Avatar
Willr

Forum Moderator, 5523 Posts

27 May 2010 at 6:30pm

Edited: 27/05/2010 6:31pm

Make sure you have the path correct. In SilverStripe the base path for PHP scripts is /sapphire/ (because the 'root' is sapphire/main.php) If I remember correctly so what every path you give to fopen has to be relative to the sapphire/ dir.

[edit heh you bet me my a couple minutes]

Hard coding the full path is risky as if you ever move the site it will break.