Help - Search - Members - Calendar
Full Version: Php Error
Zymic Webmaster Forums > Zymic Free Web Hosting > Zymic Free Web Hosting - General Discussion & Help
NightFox255
I have an include that displays recent news and matchs ect (Paintballing site) however i am getting an error message:

Warning: fclose(): supplied argument is not a valid stream resource in /www/uuuq.com/p/h/a/phalanxpaintball/htdocs/newsrecent.php

anyone know why i am getting this and a way i can fix it?

regards

NightFox
swordz
Paste the code?

swordz
NightFox255
Thats for one of the files but it's pretty much the same in all of them. I tried it on my mates server and it all worked ok so i', unsure wat is wrong. - Heres the paste of it: http://pastesite.com/4756

CODE
        <table cellpadding="0" cellspacing="5">
                <tr>
                <!--Recent Headlines-->
                    <td><?php recentnews(1); ?> </td>
              </tr>
                <tr>
                    <td><?php recentnews(2); ?> </td>
              </tr>                
                <tr>
                    <td><?php recentnews(3); ?> </td>
              </tr>                
                <tr>
                    <td><?php recentnews(4); ?> </td>
              </tr>                
                <tr>
                    <td><?php recentnews(5); ?> </td>
              </tr>                        
                <tr>
                    <td><?php recentnews(6); ?> </td>
              </tr>                                
            </table>
<?php
function recentnews($row){
    $news = fopen("data/news.txt","r") or exit("Unable to open file");
                $newscount = 0;
              while (!feof($news))
              {
                $line = fgets($news);
                $strongpos = strpos($line, "</strong>");
                $boldpos = strpos($line,"<strong>");
                if ($strongpos){
                    $header[$newscount] = substr($line, $boldpos, $strongpos + 9);
                    $newscount++;
                }
                }
                fclose("data/news.txt");
                switch ($row) {
                    case 1:
                        echo ("<a href='info.php#news" . ($newscount). "'>". $header[0]. "</a>");
                        break;
                    case 2:
                        echo ("<a href='info.php#news" . ($newscount - 1) . "'>". $header[1]. "</a>");
                        break;
                    case 3:
                        echo ("<a href='info.php#news" . ($newscount - 2) . "'>". $header[2]. "</a>");
                        break;
                    case 4:
                        echo ("<a href='info.php#news" . ($newscount-3) . "'>". $header[3]. "</a>");
                        break;
                    case 5:
                        echo ("<a href='info.php#news" . ($newscount-4) . "'>". $header[4]. "</a>");
                        break;
                    case 6:
                        echo ("<a href='info.php#news" . ($newscount-5) . "'>". $header[5]. "</a>");
                        break;
                    default:
                        break;
                        }
                }
                            
                ?>
NightFox255
It would seem that removing the fclose() command from all my files is doing the trick smile.gif
swordz
But that's bad resource handling. fclose doesn't expect a file, it expects a resource. Could have found this in the manual.

Try fclose($news);

swordz
NightFox255
yh but i've tried that in other files and it didn't work either :/ - however it seems to be working for now...
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.