473,800 Members | 2,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

file_exists does not work

This is my code:

if (file_exists($F name)) {
echo "<td>$Fname exists</td>";
} else {
echo "<td>$Fname does not exist</td>";
}

$Fname is the full path to the file I'm trying to verify. When I run the
script, I get the following output:

http://server1:8080/images/dwg_images/5005/5005001_.pdf does not exist

If I cut-and-paste the output path, the file is displayed, confirming that
the file does exist.

Am I doing something wrong? Any help will be greatly appreciated.
Aug 13 '07 #1
20 3669
Rik
On Mon, 13 Aug 2007 14:36:19 +0200, Bob Sanderson
<ne**@LUVSPAMbo bsanderson.comw rote:
This is my code:

if (file_exists($F name))
http://server1:8080/images/dwg_images/5005/5005001_.pdf does not
exist

From the manual:

File_exists:
<http://nl3.php.net/file_exists>:
"As of PHP 5.0.0 this function can also be used with some URL wrappers.
Refer to Appendix O, List of Supported Protocols/Wrappers for a listing of
which wrappers support stat() family of functionality."

HTTP wrapper:
<http://nl3.php.net/manual/en/wrappers.http.p hp>
Table O.2. Wrapper SummaryAttribut e Supported
Restricted by allow_url_fopen Yes
Allows Reading Yes
Allows Writing No
Allows Appending No
Allows Simultaneous Reading and Writing N/A
Supports stat() No <---------------------------
Supports unlink() No
Supports rename() No
Supports mkdir() No
Supports rmdir() No

Ergo: file_exists does not play nice with http:// wrappers. If you want to
verify wether an URL exists, use fsockopen()(HEA D request), or CURL.
--
Rik Wasmus
Aug 13 '07 #2
Rik <lu************ @hotmail.comwro te in
news:op.twzz8gz nqnv3q9@metalli um:
On Mon, 13 Aug 2007 14:36:19 +0200, Bob Sanderson
<ne**@LUVSPAMbo bsanderson.comw rote:
>This is my code:

if (file_exists($F name))
> http://server1:8080/images/dwg_images/5005/5005001_.pdf does not
exist


From the manual:

File_exists:
<http://nl3.php.net/file_exists>:
"As of PHP 5.0.0 this function can also be used with some URL
wrappers. Refer to Appendix O, List of Supported Protocols/Wrappers
for a listing of which wrappers support stat() family of
functionality."

HTTP wrapper:
<http://nl3.php.net/manual/en/wrappers.http.p hp>
Table O.2. Wrapper SummaryAttribut e Supported
Restricted by allow_url_fopen Yes
Allows Reading Yes
Allows Writing No
Allows Appending No
Allows Simultaneous Reading and Writing N/A
Supports stat() No <---------------------------
Supports unlink() No
Supports rename() No
Supports mkdir() No
Supports rmdir() No

Ergo: file_exists does not play nice with http:// wrappers. If you
want to verify wether an URL exists, use fsockopen()(HEA D request),
or CURL.
Thanks for the reply but I'm a beginner with PHP and frankly, don't
understand any of what you said. Is there another, simple way to
determine if a file exists?

Aug 13 '07 #3
<comp.lang.ph p>
<Bob Sanderson>
<Mon, 13 Aug 2007 12:36:19 GMT>
<Xn************ *************** *******@69.28.1 86.158>
This is my code:

if (file_exists($F name)) {
echo "<td>$Fname exists</td>";
} else {
echo "<td>$Fname does not exist</td>";
}

$Fname is the full path to the file I'm trying to verify. When I run the
script, I get the following output:

http://server1:8080/images/dwg_images/5005/5005001_.pdf does not exist

If I cut-and-paste the output path, the file is displayed, confirming that
the file does exist.
As another user its best if you check the actual folder path rather than
a http url .

You can also write it like the below if you dont want to use else .
$pass=1;

$tempname="imag es/5005/5005001.pdf";

if (!file_exists($ tempname)) {$pass=0;}

if ($pass==0) {print "<td>$tempn ame FILE NOT FOUND</td>";}

if ($pass==1) {print "<td>$tempn ame OK</td>";}

Aug 13 '07 #4
Rik
On Mon, 13 Aug 2007 15:34:27 +0200, Krustov <me@privacy.net wrote:
$pass=1;
if (!file_exists($ tempname)) {$pass=0;}
if ($pass==0) //
if ($pass==1) //
Euhm,
if(file_exists( )){
//something
} else {
//something else
}

Keep it legible for other coders, limit the amount of random variables
popping up in your script if you don't need them, and avoid
double/repeated comparisons...
--
Rik Wasmus
Aug 13 '07 #5
Rik
On Mon, 13 Aug 2007 14:59:07 +0200, Bob Sanderson
<ne**@LUVSPAMbo bsanderson.comw rote:
Thanks for the reply but I'm a beginner with PHP and frankly, don't
understand any of what you said. Is there another, simple way to
determine if a file exists?
A 'file' is not the proper term for something accessed by the HTTP
protocol. As others have indicated, if the file is on the same server, you
should use the local filesystem instead of the long way around by http.

If it is on another server however, look at the user contributed notes at
<http://www.php.net/file_exists>, several options for determining wether
an URL can be 'found' are given there.
--
Rik Wasmus
Aug 13 '07 #6
<comp.lang.ph p>
<Rik>
<Mon, 13 Aug 2007 15:38:56 +0200>
<op.twz2u6xyqnv 3q9@metallium>
$pass=1;
if (!file_exists($ tempname)) {$pass=0;}
if ($pass==0) //
if ($pass==1) //

Euhm,
if(file_exists( )){
//something
} else {
//something else
}

Keep it legible for other coders, limit the amount of random variables
popping up in your script if you don't need them, and avoid
double/repeated comparisons...
Up your arse .

I dont recall asking you for your zen like wisdom on how i should or
shouldnt write code .
Aug 13 '07 #7
Rik <lu************ @hotmail.comwro te in news:op.twz2u6x yqnv3q9@metalli um:
On Mon, 13 Aug 2007 15:34:27 +0200, Krustov <me@privacy.net wrote:
>$pass=1;
if (!file_exists($ tempname)) {$pass=0;}
if ($pass==0) //
if ($pass==1) //

Euhm,
if(file_exists( )){
//something
} else {
//something else
}
That did it. Thanks to all.
Aug 13 '07 #8
<comp.lang.ph p>
<Rik>
<Mon, 13 Aug 2007 16:36:30 +0200>
<op.twz5i4ikqnv 3q9@metallium>
Common mistake: there are very little rules, but as it is internet
No - its actually called usenet - and is merely a part of the internet .

Usenet doesnt have any heirarcial command structure and everybody is
equal with everybody having the same rights .

That is apart from people like yourself who self appoint themselves as
some sort of newsgroup arsehole who trys to dictate and decide what
other users can and cant say on 'their' newsgroup .

Aug 13 '07 #9
<comp.lang.ph p>
<Jerry Stuckle>
<Mon, 13 Aug 2007 10:58:22 -0400>
<8I************ *************** ***@comcast.com >
Rik is correct. When you post sample code, you should try to ensure it
is a good example
Who decides what is good or bad on this newsgroup - you and rik ? .
Aug 13 '07 #10

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

Similar topics

2
3761
by: Andrew Crowe | last post by:
Hi guys, I've created this little function to check whether a user has uploaded a file with the same name as an existing file, and if so rename it to file-1.jpg, file-2.jpg etc. clearstatcache(); if(file_exists("$BasePath/$FileName.jpg")){ $extra=1; while(file_exists("$BasePath/$FileName-$extra.jpg")){
10
3999
by: Google Mike | last post by:
{NOTE: I have PHP 4.2.2 for RH9 Linux.} Anyone have a better file_exists() out there? Even if you use shell out tricks with Linux using the `command` trick, I'd be interested to see what you came up with. I have this remotely mounted SMB shares on Linux, stuck in my /mnt directory, and the docs tell me that file_exists() doesn't work on that. When I tested this, I found this to be true. Therefore, I need an alternative.
1
2285
by: Hinrich Specht | last post by:
Hello, I have a problem using file_exists. I want to use file_exists to dertermine if a product-image is available or not to show either the product-image or a standard-image. This is the code: $image = "../../artimages/".$item_code.".jpg"; if (file_exists($image))
3
7972
by: annie | last post by:
Hi I've got two linux boxes running redhat9 and either PHP Version 4.2.2 or PHP Version 4.3.7. The file structure is set up the same on both machines and both files exist. The problem is not file specific and on both machines seq_tables is a symbolic link to another location. It makes no difference to either version of php whether I use double or single quotes when asigning a value to $filename. Nor does it matter whether I use...
5
8714
by: lkrubner | last post by:
I've written some template code and one thing I'm trying to protect against is references to images that don't exist. Because users have the ability to muck around with the templates after everything's been set up, there is a chance they'll delete an image or ruin some tag after the web designer has set up everything perfectly. I want the software to catch mistakes like that and, at the very least, not show broken links. On the control...
4
7021
by: dchaffin | last post by:
I'm having a problem using file_exists with an absolute path and I can not figure out why. I tried the exact example that is on www.php.net ... <?php $filename = '/path/to/foo.txt'; if (file_exists($filename)) { echo "The file $filename exists";
6
2788
by: +86 | last post by:
i encountered this problem: "include('inc.php')" will work problely but "include('./inc.php') doesn't work .. both file_exists('inc.php') or file_exists('./inc.php') didn't return the right value.this always show "file doesn't exists' my environment is win2003+iis+php5 how to fix it ?
15
9115
by: cooldht | last post by:
Hi all, I ran into a cool function in a google search, called file_exists that would do exactly what I need it to do. Unfortunately, I think something is wrong with the logic I'm using, because it returns a value of null instead of true or false. It seems to work great if I check for something in the base directory, but when I try something outside of the root, it fails. The check file code looks like this: if (file_exists($filename)) { ...
3
2071
by: rickcasey | last post by:
I'm using PHP 4.4.4-8 on Debian Linux on a low traffic site, and need to detect if a file exists, and if so, unlink it. I am mystified as to why the file_exists() function does not work in one particular section of code, yet does work in another section. The unlink() function similarly works in one section, but not the other. I have read other posts in this group where others have had trouble with the file_exists() function, but none...
0
9691
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10505
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10276
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10035
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7580
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6813
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.