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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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   1018 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.