Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-04-2012, 01:06 PM   PM User | #1
ska_defender
New Coder

 
Join Date: Jul 2012
Posts: 25
Thanks: 3
Thanked 0 Times in 0 Posts
ska_defender is an unknown quantity at this point
Warning: fclose(): supplied argument is not a valid stream resource

I am getting the warning on my pages
Warning: fclose(): supplied argument is not a valid stream resource

Using the following code:
PHP Code:
$fp fopen('data.txt''w');
$write '2';
fwrite($fp$write);
fclose($fp); 
ska_defender is offline   Reply With Quote
Old 08-04-2012, 04:32 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,645
Thanks: 4
Thanked 2,450 Times in 2,419 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
You should also have an error on the fwrite. fclose should only be throwing that if $fp isn't a valid stream, which indicates that your fopen has also failed.
Use an if to determine if continuation is possible:
PHP Code:
if ($fp fopen('data.txt''w'))
{
    
fwrite($fp2);
    
fclose($fp);

Fou-Lu is offline   Reply With Quote
Old 08-05-2012, 12:43 PM   PM User | #3
ska_defender
New Coder

 
Join Date: Jul 2012
Posts: 25
Thanks: 3
Thanked 0 Times in 0 Posts
ska_defender is an unknown quantity at this point
This is the full code

PHP Code:
if(isset($_REQUEST['go1']))
{


$fp fopen('data.txt''w');
$write '1';
$fp1 fopen('file.php''w');
$write1 '<br><img src="/1/online.png" style="position:absolute; z-index:-2;" />';

}
if(isset(
$_REQUEST['go2']))
{



$fp fopen('data.txt''w');
$write '2';
$fp1 fopen('file.php''w');
$write1 '<br><img src="/1/offline.png" style="position:absolute; z-index:-2;" />';

}

fwrite($fp$write);
fclose($fp);
fwrite($fp1$write1);
fclose($fp1);

$fp fopen('data.txt''r');
$contents fread($fpfilesize('data.txt'));
fclose($fp);
if(
$contents == '1')
include(
'file.php');
else if(
$contents == '2')
include(
'file.php');
else
echo 
'Something else...'
ska_defender is offline   Reply With Quote
Old 08-05-2012, 01:27 PM   PM User | #4
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
I don't know what the issue is, but concerning 'fread'

Quote:
If you just want to get the contents of a file into a string, use file_get_contents() as it has much better performance
Perhaps try file_get_contents() instead.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 02:09 PM.


Advertisement
Log in to turn off these ads.