Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with fopen function

Status
Not open for further replies.

mlara

Programmer
Oct 22, 2001
32
CO
Hello.

I have a problem with the fopen function. I write the follow:

$fp = fopen("filename", "r");

or

$fp = fopen(" "r");

In the first case, the return value is null or false. In the second case apparently too is null or false.

However the display messages in both cases respectively:

Warning: fopen("filename","r") - No such file or directory in ...

Warning: fopen(" - Success in ...

In the second case apparently the file was open successful, but try use it, $fp is null or false.

Thansk.
 
How are you verifying that the value in $fp is FALSE?

______________________________________________________________________
TANSTAAFL!
 
Thanks you.

I already resolve the problem. I change the filename that originally was "name.cvs" per "name.txt", and tha fopen function was successful.

Why not is successful the execution of the fopen function when the extension filename is cvs?

---

In this way I verify that $fp is null or false.

if(!$fp)
$fp is null or false
else
$fp not is false

 
If you don’t get a good filehandle when opening a file, then I always ask two questions: Does the file exist? Does your script have permissions to read the file?

When testing a handle for whether it is FALSE or not, I recommend using PHP’s “===” operator. For example:

Code:
if($fp === FALSE)
  $fp is null or false
else
  $fp not is false

It makes your code more readable, and it bypasses any problems you might one day run into with PHP’s running on multiple platforms. ______________________________________________________________________
TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top