473,406 Members | 2,849 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,406 software developers and data experts.

file() doesn't work

Hi All,
Ok, here's my problem. I want to open a file and process its contents.
However, because it is possible that the file may not exist, I also want to
check whether the file() function is successful before attempting to process
any returned data from the file() function. The php file() manual page
suggests that it returns FALSE if it is unsuccessful, however this simply
doesn't happen on my system. My code looks like the following:
if (($file_contents =
(file("http://www.mydomain.com/some_file_that_doesnt_exist.dat"))) == FALSE)
{
echo "Your file doesn't exist!!";
}
else
{
do_some_interesting_processing ($file_contents);
}

Even something like the following doesn't work:

if (file("http://www.mydomain.com/some_file_that_doesnt_exist.dat") ==
FALSE)
{
echo "Your file doesn't exist!!";
return;
}

The file() function doesn't return FALSE as suggested.

So what's going on?. Why doesn't this work?. Is there another/better way of
knowing whether the file() function was successful?.

Regards,
Dave
Dec 28 '05 #1
3 1799
Wouldn't

if( !file('file.dat') )
{
echo 'doesnt work';
}

work?

Dec 28 '05 #2
Dave Moore wrote:
Hi All,
Ok, here's my problem. I want to open a file and process its
contents. However, because it is possible that the file may not
exist, I also want to check whether the file() function is successful
before attempting to process any returned data from the file()
function. The php file() manual page suggests that it returns FALSE
if it is unsuccessful, however this simply doesn't happen on my
system. My code looks like the following:


It does work as is demonstrated with the following:

print file('http://example.com/lost') == false ? 1 : 0;

Have a look at what the file() function call actually returns (e.g., with
print_r()). Chances are that because of some directive, your webserver does
not return a 404 response code, but redirects with a 301/302 response code
to some other page.
JW
Dec 28 '05 #3
Thanks. That seems to be working now.

Ta,
Dave

"Janwillem Borleffs" <jw@jwscripts.com> wrote in message
news:43***********************@news.euronet.nl...
Dave Moore wrote:
Hi All,
Ok, here's my problem. I want to open a file and process its
contents. However, because it is possible that the file may not
exist, I also want to check whether the file() function is successful
before attempting to process any returned data from the file()
function. The php file() manual page suggests that it returns FALSE
if it is unsuccessful, however this simply doesn't happen on my
system. My code looks like the following:
It does work as is demonstrated with the following:

print file('http://example.com/lost') == false ? 1 : 0;

Have a look at what the file() function call actually returns (e.g., with
print_r()). Chances are that because of some directive, your webserver

does not return a 404 response code, but redirects with a 301/302 response code
to some other page.
JW

Dec 28 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: | last post by:
Hello, I hope someone will help me or I will have to dive from 11th floor. Why this --> test = @"Melanie "Jets" Riggs" doesnt work in asp? I need something like that and I dont know how to make it...
11
by: Savas Ates | last post by:
CREATE PROCEDURE st_deneme @userid numeric (18) ,@result numeric (18) output AS select * from users return "10" GO **************************** <!--METADATA TYPE="typelib" NAME="Microsoft...
1
by: Station Media | last post by:
Hi, here my problem, i use stored procedure in ACCESS database(latest version), and i would like to use this procedure but it doesnt work, do you know why ? Procedure: PARAMETERS MyField Text...
3
by: Clouds | last post by:
Hi ! How do I add the dynamic event handler for a dropdownlist present in the itemtemplate of a datalist !! I am doing it in the itemdatabound event of the datalist but it doesnt work... I am...
2
by: thechaosengine | last post by:
Hi eveyone, If anyone could advise on the following I would be truly greatful: I have a fairly standard set up. An IIS 5.1 website set up with anonymous access allowed in all areas of the site...
0
by: Juna | last post by:
I have been working in vs2003, but now started to work in vs2005 but the problem, I have simple web application not website, which work i mean open in browser when we press F5 or run the...
1
Digital Don
by: Digital Don | last post by:
I am writing a program for Peg solitaire... To check for no repetition of previous states I use a Set for storage of Board states.. The pronblem is when I declare the set as type char i.e. set...
3
by: jx2 | last post by:
hi guys i would appriciate your coments on this code - when i ran it for the very first time it doesnt see @last = LAST_INSERT_ID() but when i ran it next time it read it properly i need to know it...
1
by: Dany13 | last post by:
hi all. i using some text box for input value and some localvarible for passing this data to dataset . give instance for correct row of dataset and data in data table . use one gird view for...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.