I have this section in a script of mine:
PHP Code:
@$info= fopen('/home/myuser/info.txt','r'); if (!$info) { echo "[-] Error : coudn't read /home/myuser/info.txt"; exit; }
this always ends as Couldn't read. So I tried only running
PHP Code:
fopen('/home/myuser/info.txt','r');
and I got a blank response. So I tried changing the function to
PHP Code:
readfile('/home/myuser/info.txt','r');
That seemed to work, the file was read. Now I changed that in my script and next thing I know I get this error:
Code:
Warning: feof(): supplied argument is not a valid stream resource in /path/to/my/script.php on line 17
Warning: fgets(): supplied argument is not a valid stream resource in /path/to/my/script.php on line 18
Line 17 and 18 in the script contain the following:
PHP Code:
while(!feof($info)) { $str=fgets($info);
I presume I need to change these functions too now that I have changed the fopen? What do I change it to to fix it? I greatly appreciate any help! Thank you in advance!
Edit: On a side note, could you recommend an alternative fix to changing the fopen to readfile()?
Edit2: Excuse the stupidity, I'm a little tired. I just remembered that for feof to work it must point to a file successfully opened by fopen(). Would any of you expert coders be able to suggest a replacement for this code, so I can use readfile() instead? Or even better would be that if the fopen section fails, it tries again, but with the readfile or another alternative. Much appreciate any support... Thank you.
Last edited by locoputo; 04-28-2010 at 07:36 AM..
|