471,319 Members | 1,632 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

Error with fopen() function

196 100+
So the function fopen() works most of the time heres the line im using-

Expand|Select|Wrap|Line Numbers
  2. $file = fopen($nextPage, "r") or exit("Unable to open file!");
But for some reason that i haven't been able to discern yet im getting "Unable to open file!" on specific urls this wouldn't be so much of a problem but it ends up hanging the rest of the program up.

Anyway so far i cant see any reason for the errors to occur becuase when theres a error i manually type in the url into a browser it works fine even though im getting a connection error.

So if anyone can help understand why there is an error occuring or better yet a way to skip a function if a error occurs.

Oh yer even if i continually repeat the the function i still get a connection error over and over again so i doesn't seem to be just a single random error.

Any helps with this problem is greatly appreciated,

Thanks in advance,
Jan 19 '09 #1
6 1692
1,584 Expert 1GB
This is generally a basic function. There's not much code there to "help" you debug. All you need to do is check to make sure the $nextPage variable is going to a correct path. It wouldn't hurt to just echo that variable.

As far as the exiting when a function fails, this is PHP default fault exception behavior. PHP exits when a fatal error occurs, whether or not display_errors is on. You need to remove that "or exit(....)" part (because that exits the processes if the function returns false or errors) and then put a @ sign infront of the function to suppress that function (such as @fopen() )

Hope that helps,

Jan 19 '09 #2
196 100+
Thanks ill try that out
Jan 19 '09 #3
196 100+
Ok just have one question when you said put @ in front of the function call to suppress it is this supposed to be at run time (when it compiles) or before??

Also i don't suppose there is a goto command in php??

Thanks for the help
Jan 19 '09 #4
5,821 Expert 4TB
Heya, Chazzy.

The '@' operator suppresses any errors that a PHP statement generates (PHP: Error Control Operators - Manual).

Generally, you will see this error if Apache does not have read permissions for the file you're trying to open.
Jan 19 '09 #5
196 100+
Oh sweet thanks i get it now
Jan 19 '09 #6
196 100+
I fixed the problem thanks for your help pplz
Jan 19 '09 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Phil Powell | last post: by
22 posts views Thread by Amali | last post: by
9 posts views Thread by i | last post: by
7 posts views Thread by i | last post: by
70 posts views Thread by junky_fellow | last post: by
5 posts views Thread by chazzy69 | last post: by
63 posts views Thread by Kapteyn's Star | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.