2

When I am trying to do this:

$txt = file_get_contents('http://stats.pingdom.com/file'); 
file_put_contents('/stats/file.html',$txt);

I am getting following error:

Warning: file_put_contents(stats/stats.html) [function.file-put-contents]: failed to open stream: Permission denied in /home/jtf/public_html/index.php on line 2

the folder stats is 777

what am I doing wrong?

thanks

J.K.A.
  • 7,272
  • 25
  • 94
  • 163
Chriswede
  • 935
  • 2
  • 12
  • 31

4 Answers4

3

/stats and stats (or the equivalent, ./stats) are not necessarily the same directory (in fact they might refer to the same directory only in theory). Most likely you are currently trying to write to a directory that does not even exist.

So this should work:

file_put_contents('stats/file.html',$txt); // removed "/" prefix
Jon
  • 428,835
  • 81
  • 738
  • 806
1

Try this:

$txt = file_get_contents('http://stats.pingdom.com/file');
file_put_contents(dirname(__FILE__) . '/stats/file.html', $txt);
Rick Kuipers
  • 6,616
  • 2
  • 17
  • 37
1

There is no /stats/ folder in the root directory on your server, I believe.

Note the /home/jtf/public_html/ path. You have to use this one to address files in the document root of your web-server.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
0

Your path points to / instead to /home/jtf/public_html/
Just use ../

Remc4
  • 1,044
  • 2
  • 12
  • 24