Jump to content

PhP file read error

mider
Go to solution Solved by Brenz,

You are only using a single equals sign, this means you are trying to set 

fread($currentStream,filesize("control/current.txt"))

to be netflix which obviously you cannot do.

 

In an IF statement you can either use two or three equals signs.

Two will compare ignoring the case so an integer could equal a string like 2 == '2'.

Three will only be true if the type and value match so 2 === 2 is true, 2 === '2' is false and '2' === '2' would be true.

 

Then your string needs to be wrapped in quotes or it won't work.

 

So in your case it should be:

 

if (fread($currentStream,filesize("control/current.txt")) === "netflix") ?>

Hi!  So to put this very simply, i made a program that can access different streaming services for my home theater setup.  I am making a web control for it and I'm having trouble with PhP.  I want it to detect if a file contains (or equals) "netflix" and for it to spit out in html: Currently Watching: Netflix

here is my current code:

 

 

<?php
$currentStream = fopen("control/current.txt", "r") or die("Unable to open file!");
if (fread($currentStream,filesize("control/current.txt")) = netflix) ?>
  <h2>Currently Watching: Netflix</h2>
<?php
endif
?>

 

 

 

 

The error I am getting says:

 Fatal error: Can't use function return value in write context in C:\wamp\www\structure.php on line 41

Line 41 is the line the one that says:

 

if (fread($currentStream,filesize("control/current.txt")) = netflix) ?>

 

CPU: AMD FX-6300 @3.8 GHz     |     Cooling: Cooler Master Hyper Evo 212     |     RAM: G.Skill NS Series 4x4GB      |       Motherboard: GIGABYTE 990FXA     |     Case: Antec One     |     Video Card: MSI Radeon R9 270x HAWK    |    PSU: EVGA SuperNova 750 G2    |     HDD: 1 WD Black (Programs Files), 1 WD Caviar Blue (Boot)     |     KB & M: Cooler Master Storm Devastator Blue     |     Speakers: Logitech Z506     |     UPS:  CyberPower 1500w     |

 

Every time you use comic sans, one programmer dies.

Link to comment
Share on other sites

Link to post
Share on other sites

You are only using a single equals sign, this means you are trying to set 

fread($currentStream,filesize("control/current.txt"))

to be netflix which obviously you cannot do.

 

In an IF statement you can either use two or three equals signs.

Two will compare ignoring the case so an integer could equal a string like 2 == '2'.

Three will only be true if the type and value match so 2 === 2 is true, 2 === '2' is false and '2' === '2' would be true.

 

Then your string needs to be wrapped in quotes or it won't work.

 

So in your case it should be:

 

if (fread($currentStream,filesize("control/current.txt")) === "netflix") ?>
Link to comment
Share on other sites

Link to post
Share on other sites

40 minutes ago, Brenz said:

You are only using a single equals sign, this means you are trying to set 


fread($currentStream,filesize("control/current.txt"))

to be netflix which obviously you cannot do.

 

In an IF statement you can either use two or three equals signs.

Two will compare ignoring the case so an integer could equal a string like 2 == '2'.

Three will only be true if the type and value match so 2 === 2 is true, 2 === '2' is false and '2' === '2' would be true.

 

Then your string needs to be wrapped in quotes or it won't work.

 

So in your case it should be:

 


if (fread($currentStream,filesize("control/current.txt")) === "netflix") ?>

THANK YOU SO MUCH!! Lol I could not figure out what i was doing wrong.  I wanted to post this on StackExchange but I have only ever posted a couple questions and i've been banned.  Probably cause i haven't used it in like a year

CPU: AMD FX-6300 @3.8 GHz     |     Cooling: Cooler Master Hyper Evo 212     |     RAM: G.Skill NS Series 4x4GB      |       Motherboard: GIGABYTE 990FXA     |     Case: Antec One     |     Video Card: MSI Radeon R9 270x HAWK    |    PSU: EVGA SuperNova 750 G2    |     HDD: 1 WD Black (Programs Files), 1 WD Caviar Blue (Boot)     |     KB & M: Cooler Master Storm Devastator Blue     |     Speakers: Logitech Z506     |     UPS:  CyberPower 1500w     |

 

Every time you use comic sans, one programmer dies.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×