Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Changing fopen to readfile messes up script. Any ideas?
Old 04-27-2010, 09:02 PM Changing fopen to readfile messes up script. Any ideas?
Junior Talker

Posts: 3
Trades: 0
I have this section in a script of mine:
PHP Code:
@$infofopen('/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..
locoputo is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-28-2010, 01:29 AM Re: Changing fopen to readfile messes up script. Any ideas?
Skilled Talker

Posts: 84
Name: Jonthy
Trades: 0
You are using right coding no need to change on it.
__________________

Please login or register to view this content. Registration is FREE
itandseoservice is offline
Reply With Quote
View Public Profile
 
Old 04-28-2010, 07:15 AM Re: Changing fopen to readfile messes up script. Any ideas?
Junior Talker

Posts: 3
Trades: 0
But fopen doesn't want to work? It can't load the file, meaning the rest of the script fails? Is there any way I can change the script so it uses a different function?

Last edited by locoputo; 04-28-2010 at 07:18 AM..
locoputo is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Changing fopen to readfile messes up script. Any ideas?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.25012 seconds with 12 queries