Jump to:

23361 Posts in 18124 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » Fetch Data from Text File

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

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

Page: 1
Go to End
Author Topic: 780 Views
  • akshu
    Avatar
    Community Member
    7 Posts

    Fetch Data from Text File Link to this post

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

  • akshu
    Avatar
    Community Member
    7 Posts

    Re: Fetch Data from Text File Link to this post

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

  • Willr
    Avatar
    Forum Moderator
    5483 Posts

    Re: Fetch Data from Text File Link to this post

    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.

    780 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.