Fopen() problems

software development

#1

Ok well I’m new at working with php. But from what I understand php IS enabled on my website. I’m trying to figure out why I am getting an error msg when I use fopen()

Here’s the php script I’m using:
[color=#00CC00]

<?php $fr = fopen(realpath('/home/dennis01/news.txt'), 'r'); $data = fread($fr, filesize($fr)); fclose($fr); ?>

[/color]

Now when I run the php it seems to open something but when it attempts to use fread and filesize it gives me this error:

[color=#CC0000]
Warning: filesize(): Stat failed for Resource id #1 (errno=2 - No such file or directory) in /home/.faysidiousblender/dennis01/waddellconsulting.com/php/index.php on line 13

Warning: fread(): Length parameter must be greater than 0. in /home/.faysidiousblender/dennis01/waddellconsulting.com/php/index.php on line 13
[/color]

Any help is appreciated. I’m more than willing to learn, and I will continue to check google for the answers.

Matthew


#2

It’s not a problem with fopen()

The parameter to filesize() is supposed to be the filename, not a resource:

<?php $filename = "/home/dennis01/news.txt"; $filesize = filesize($filename); $fr = fopen(realpath($filename), 'r'); $data = fread($fr, $filesize); fclose($fr); ?> :cool: Perl / MySQL / HTML+CSS


#3

Thanks so much, that sure explains alot lol.

I can’t wait till I’ve got this added to my list of experience.