For pset8, fopen() keeps returning FALSE. The relevant part of my code is below:

#!/usr/bin/env php
$file = ($argv[1]);

if(file_exists($file) == 0)
    exit("File does not exist.\n");
echo "File exists. \n";

$handle = fopen("$file","r");
if ($handle == FALSE);
    exit("fopen failed \n");

//rest of code

When I run import with

./import /home/ubuntu/workspace/pset8/bin/US.txt

it returns "File exists" and "fopen failed". I've checked all my chmod permissions, directory paths, and the fopen usage manual. It seems like a straightforward step, but is there something obvious that I'm missing? Thanks so much in advance!!

1 Answer 1


You added an extra unwanted ; on this line:

if ($handle == FALSE);

Remove the semicolon and it will work as wanted.

  • 1
    Oh my goodness, I feel quite ridiculous now. Thank you so much!
    – WGF56
    Aug 1, 2016 at 7:34
  • Np. We've all been there.
    – ChrisG
    Aug 1, 2016 at 9:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .