/    Sign up×
Community /Pin to ProfileBookmark

Warning message

This may be really simple
but I am just learning php and when I try to load a page on my computer I get this message
Warning: fclose(): supplied argument is not a valid stream resource in C:webserverApache2htdocsscores.php on line 9
What does it mean and what do I have to do to resolve it?
Thanks
Brett

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@NogDogAug 21.2006 — It means that the argument you passed to the fclose() function is not a valid resource ID returned by a prior fopen() call. Without seeing the source code, that's about all we can tell you.
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYAug 21.2006 — actually we can suppose that the file wasn't successfully opened and thus no resource pointer was attributed to that variable.

just make sure the variable isn't [B]false[/B] and it should be alright, e.g.:
[code=php]
<?php

$handle = fopen('somefile.txt', 'r');
if(!$handle){
# ..do what you want with the file
fclose($handle);
}else{
die("Error: There was a problem opening the file, check the path/location");
}

?>
[/code]
Copy linkTweet thisAlerts:
@Ahmed_TohamyAug 21.2006 — This may be really simple

but I am just learning php and when I try to load a page on my computer I get this message

Warning: fclose(): supplied argument is not a valid stream resource in C:webserverApache2htdocsscores.php on line 9

What does it mean and what do I have to do to resolve it?

Thanks

Brett[/QUOTE]


let us see the code and be sure that you'll get the help for it

or just tell us what you exactly need to do
Copy linkTweet thisAlerts:
@urbunnerauthorAug 21.2006 — Here is the code from a tutorial on Flash Kit by Glen Rhodes

Basically I need to make a highscore board for a card game but its going to be kept on my system and not posted to the net
[code=php]<?php

$winscore = (int)$winscore;

// Create a Blank File if it doesn't already exist
if (!file_exists($filename))
{
$file=fopen($filename, "highscores");
fclose ($filename);
}

// Read the file in
$oscores = file ($filename);
$numreadin = count($oscores);

// Break out the data into a new 2-d array called $tscores
for ($i = 0; $i < $numreadin; $i++)
{
$g = unserialize($oscores[$i]);
$tscores[$i][0] = $g[0];
$tscores[$i][1] = $g[1];
}

// Fill in any missing data with none/0
for ($i = $numreadin; $i < $scoresize; $i++)
{
$tscores[$i][0] = 0;
$tscores[$i][1] = "none";
}

// Process the actions

// Insert a score/name
if ($action == "INSERT")
{

// Add name to end of list, and sort
$tscores[$scoresize + 1][0] = $winscore;
$tscores[$scoresize + 1][1] = $winname;
rsort ($tscores);

$file=fopen($filename, "w");

// Write them out
for ($i = 0; $i < $scoresize; $i++)
{
$st = serialize($tscores[$i]) . "n";
fputs($file, $st);
}

fclose($file);
}

// Clear the list
if ($action == "CLEAR")
{

$k[0] = 0;
$k[1] = "none";
$ser = serialize($k);

$file=fopen($filename, "w");

for ($i = 0; $i < $scoresize; $i++)
{
$st = $ser . "n";
fputs($file, $st);
}

fclose($file);
}

// Process the OUTPUT options
if ($viewtype == "HTML")
{
// HTML PAGE CREATED HERE
?>


<table cellpadding=2 cellspacing=2 border=0 width="152">
<tr align=center>
<th bgcolor="#000033"><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">#</font></th>
<th bgcolor="#000033"><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">Name</font></th>
<th bgcolor="#000033"><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">Score</font></th>
</tr>

<?

for ($i = 0; $i < $scoresize; $i++)
{
echo ("<tr bgcolor='#666666' align='center'><td><font size='2' face='Arial, Helvetica, sans-serif'>");
echo ($i + 1);
echo ("</font></td><td><font size='2' face='Arial, Helvetica, sans-serif'>");
echo ($tscores[$i][1]);
echo ("</font></td><td><font size='2' face='Arial, Helvetica, sans-serif'>");
echo ($tscores[$i][0]);
echo ("</font></td></tr>");
}

?>
</table>
<?

}

// FLASH DATA CREATED HERE
if ($viewtype == "FLASH")
{
for ($i = 0; $i < $scoresize; $i++)
{
echo ("NAME" . $i . "=");
echo ($tscores[$i][1]);
echo ("&SCORE" . $i . "=");
echo ($tscores[$i][0]);
echo ("&");
}
}

?>
[/code]

Thanks

Brett
Copy linkTweet thisAlerts:
@NogDogAug 21.2006 — This...
[code=php]
// Create a Blank File if it doesn't already exist
if (!file_exists($filename))
{
$file=fopen($filename, "highscores");
fclose ($filename);
}
[/code]

...should be something more like this...
[code=php]
// Create a Blank File if it doesn't already exist
if (!file_exists($filename))
{
$file=fopen($filename, "w"); // "highscores" is not a valid mode
if(!$file) { die("fopen() failed to create new file"); }
fclose ($file); // close the file handle, not the file name
}
[/code]
Copy linkTweet thisAlerts:
@urbunnerauthorAug 21.2006 — Here is the link to the tutorial

http://www.flashkit.com/tutorials/Games/High-sco-Glen_Rho-657/index.php

on page 2 where it says it should display a highscores table all I get is this

fopen() failed to create new file I am using the localhost on my machine rather then his www.myscore.com

Thanks for all the help

Usually I post something and get zero response

I appreciate the communication
Copy linkTweet thisAlerts:
@NogDogAug 21.2006 — Try adding the following line at the very beginning of your script, to see if we can get PHP to tell us more:
[code=php]
error_rerporting(E_ALL);
[/code]
×

Success!

Help @urbunner spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...