Page 1 of 3 123 LastLast
Results 1 to 10 of 25

Thread: fclose() error and can't figure it out!

  1. #1
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default fclose() error and can't figure it out!

    Hello everyone... hopefully this will be quick:

    I have a flash game that writes the submitted final score and log in name to the highscores list through php (no SQL here)

    Everything is set up, everything works, and get this: on another site the scores work perfectly!

    Now when I take all the files off the test site and place them on the final resting place site the highscores wont work (and yes I changed ALL instances of global.domain= LOL)

    I have traced the error and made a report, and I get this:

    PHP Warning: fclose(): supplied argument is not a valid stream resource in /my/domain/and/path/to/scores.php on line 9

    line 9 of the scores.php looks like this:

    fclose ($file);


    with the whole lines upto there as this:

    <?php

    $winscore = (int)$winscore;

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


    So, with this error pointing to the php, I am guessing it is there? Anyone know how to get by this?

    Thanks!
    ________
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    The only possible problem here is if $filename can't be written. Check that the user your scripts run as has write permission to the directory in which you're attempting to create this file.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    ALL files in this directory have either a 755 or a 777 CHMOD. Is this what you mean? Or something else?
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    What about the directory itself?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    The directory itself is 777 as is the sub-directory...

    now you see my problem? LOL
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Are you sure $filename contains what you expect it to contain? Try echoing it before you call fopen().
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    I have been fighting with this for about 2 months now. I am not sure of anything anymore.

    $filename makes a file called highscores.sco if it doesn't exist yet. Which it doesn't. The first time someone played the game and submits a highscore, it should create the highscores.sco file and write the name and score to it.

    then the page is displayed. Everything works except the name and score doesn't get written and the highscores.sco file doesn't get created.

    I just don't understand it.

    *****************

    <edit> I just did a double check, the folders are only 755. if I try to CHMOD them to 777 I get 500 errors when trying to access the html inside them... could this be the problem?

    Alos I did the echo and it gave the same error the error log did about line 9 and the fclose() I don't know what an fclose() does exactly, I am guessing it closes the file after the writing has been done...

    </edit>
    Last edited by BLiZZaRD; 04-03-2006 at 07:17 PM.
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Alos I did the echo and it gave the same error the error log did about line 9 and the fclose() I don't know what an fclose() does exactly, I am guessing it closes the file after the writing has been done...
    You did echo($filename); before the fopen() call? Can you show me the output? You're right about the function of fclose().
    If you touch and chmod 777 highscores.sco before running the script, does it work?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    no, maybe I didn't do that. I am so confused right now my brain hurts.

    here is the entire scores.php:

    Code:
    <?php
    
    	$winscore = (int)$winscore;
    
    	// Create a Blank File if it doesn't already exist
    	if (!file_exists($filename))
    	{
    		$file=fopen($filename, "w");
    		fclose ($file);
    	}
    
    	// 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] = "";
    	}
    
    	// 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] = "no-one";
    		$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="330">
      <tr align=center> 
        <th bgcolor="#663300" width="80"><font color="#ffff00" face="Arial, Helvetica, sans-serif" size="1">Rank</font></th>
        <th bgcolor="#663300" width="126"><font color="#FFFF00" face="Arial, Helvetica, sans-serif" size="1">Name</font></th>
        <th bgcolor="#663300" width="104"><font color="#FFFF00" face="Arial, Helvetica, sans-serif" size="1">Score</font></th>
      </tr>
      <?
    	
    		for ($i = 0; $i < $scoresize; $i++)
    		{
    			echo ("<tr bgcolor='#669933' align='center'><td><font size='1' face='Arial, Helvetica, sans-serif'>");
    			echo ($i + 1);
    			echo ("</font></td><td><font size='1' face='Arial, Helvetica, sans-serif'>");
    			echo ($tscores[$i][1]);
    			echo ("</font></td><td><font size='1' 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 ("&");
    		}
    	}
    
    ?>
    if I browse to it I get the WARNING: fclose().... thing

    If I try to add the echo($filename); at the top I get a parse error.

    the thing works like this: (for clarification)

    I have root folder(755)>>game folder(755)>>scores folder(755)>>highscores.sco(777)

    the html(755) and game.swf(755) are in game folder.
    also scores.php (the above code) is in game folder and also (777).

    the link in the swf tells scores.php to start doing its thing, and tells it that the global domain is my domain and the .sco is at scores/highscore.sco

    All of that is set up exactly the same, and works on the other site. when I copy the files over from the test site to my permanent site everything works but the scores. They stay blank.

    Thanks for helping me out (again) Twey
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    All of that is set up exactly the same, and works on the other site.
    Right. Sounds like the scores folder isn't owned by the user your scripts run as. Save this PHP script as whoami.php:
    Code:
    <?php echo(`whoami`); ?>
    then
    Code:
    $ chown -R `php whoami.php` scores
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •