fclose()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Grammatron
Forum Newbie
Posts: 4
Joined: Mon Feb 09, 2004 1:52 pm

fclose()

Post by Grammatron »

I keep getting fclose Warnings on my site: http://207.36.204.49/gallery/disney/vintagemickey/ Everything seems to work fine regardless and if I remove the fclose line in the code the warnings go away. However I was wondering what is causing them so I can fix the problem instead of just making the warning go away.
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

maybe if we saw your code then we could help you....
Grammatron
Forum Newbie
Posts: 4
Joined: Mon Feb 09, 2004 1:52 pm

Post by Grammatron »

Sure thing!

$title = fopen('title.txt','r');
$title = fgets($title, 4096);
fclose($title);

$thumbs = fopen('thumbs.txt','r');
$thumbs = fgets($thumbs, 4096);
fclose($thumbs);

$big = fopen('big.txt','r');
$big = fgets($big, 4096);
fclose($big);
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

try using a different variable name for the fgets()...

Code: Select all

$title = fopen('title.txt','r'); 
$title2 = fgets($title, 4096); 
fclose($title); 

$thumbs = fopen('thumbs.txt','r'); 
$thumbs2 = fgets($thumbs, 4096); 
fclose($thumbs); 

$big = fopen('big.txt','r'); 
$big2 = fgets($big, 4096); 
fclose($big);
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

Well you are reasigning the variables to the output. Since I am assuming you want to use the fgets() info you might want to do something like this:

Code: Select all

<?php
$title_handle = fopen('title.txt','r');
$title = fgets($title_handle, 4096);
fclose($title_handle);

$thumbs_handle = fopen('thumbs.txt','r');
$thumbs = fgets($thumbs_handle, 4096);
fclose($thumbs_handle);

$big_handle = fopen('big.txt','r');
$big= fgets($big_handle, 4096);
fclose($big_handle);
?>
Edit
Damn, you beat me to it :wink:
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

:-D sorry!! I'll let you take th eeasy ones fom now on!! hehe j/k
Grammatron
Forum Newbie
Posts: 4
Joined: Mon Feb 09, 2004 1:52 pm

Post by Grammatron »

Thank you for the reply!

The solution does not work out as instead of the contents of title.txt it now says "Resource id #3" for some reason.
Grammatron
Forum Newbie
Posts: 4
Joined: Mon Feb 09, 2004 1:52 pm

Post by Grammatron »

I take it back. Your solution worked, I just found where else the code

Code: Select all

$title = fopen('title.txt','r');	
$title_2 = fgets($title, 4096);
 fclose($title);
needs to change

Code: Select all

$add_text = array( 'txt_title' => $title_2 ,
'txt_thumbs' => $thumbs_2 ,
'txt_big' => $big_2 ,
);
So, thank you very much!
Post Reply