473,394 Members | 1,887 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 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
  1.  
  2. $file = fopen($nextPage, "r") or exit("Unable to open file!");
  3.  
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 1981
dlite922
1,584 Expert 1GB
@chazzy69
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,




Dan
Jan 19 '09 #2
chazzy69
196 100+
Thanks ill try that out
Jan 19 '09 #3
chazzy69
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
pbmods
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
chazzy69
196 100+
Oh sweet thanks i get it now
Jan 19 '09 #6
chazzy69
196 100+
I fixed the problem thanks for your help pplz
Jan 19 '09 #7

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

Similar topics

0
by: Phil Powell | last post by:
<?php class FileRemoval { var $fileNameArray, $isRemoved, $errorMsg = ''; function FileRemoval() { // CONSTRUCTOR $this->fileNameArray = array(); $this->isRemoved = 0; }
39
by: ferrad | last post by:
I am trying to open a file for appending. ie. if the file exists, open it for appending, if not, create it. I am getting back a NULL pointer, and do not know why. Here is my code: FILE...
22
by: Amali | last post by:
I'm newdie in c programming. this is my first project in programming. I have to write a program for a airline reservation. this is what i have done yet. but when it runs it shows the number of...
9
by: i | last post by:
#include<stdio.h> #include<conio.h> #include<process.h> #include<string.h> char ch; int n,m; void main(); char check(int,int,char); void cash(int,int,char); void debit_card(int,int,char);
7
by: i | last post by:
#include<stdio.h> #include<conio.h> #include<process.h> #include<string.h> char ch; int w; int n,m; //void main(); char check(int n,int m,char ch); void cash(int n,int m,char ch);
70
by: junky_fellow | last post by:
Guys, If main() calls some function func() and that function returns the error (errno), then does it make sense to return that value (errno) from main. (in case main can't proceed further) ? ...
6
by: tgnelson85 | last post by:
Hello, C question here (running on Linux, though there should be no platform specific code). After reading through a few examples, and following one in a book, for linked lists i thought i would...
5
by: chazzy69 | last post by:
The error : http://www.somesite.com Warning: fopen() : php_network_getaddresses: getaddrinfo failed: Name or service not known in /etc/etc/etc/etc/test.php on line 766 Warning:...
63
by: Kapteyn's Star | last post by:
Hi newsgroup The program here given is refused by GCC with a error i cannot understand. It says rnd00.c: In function ‘main’: rnd00.c:26: error: expected expression before ‘]’ token ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.