473,385 Members | 1,736 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,385 software developers and data experts.

file_exists does not work

This is my code:

if (file_exists($Fname)) {
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 3624
Rik
On Mon, 13 Aug 2007 14:36:19 +0200, Bob Sanderson
<ne**@LUVSPAMbobsanderson.comwrote:
This is my code:

if (file_exists($Fname))
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.php>
Table O.2. Wrapper SummaryAttribute 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()(HEAD request), or CURL.
--
Rik Wasmus
Aug 13 '07 #2
Rik <lu************@hotmail.comwrote in
news:op.twzz8gznqnv3q9@metallium:
On Mon, 13 Aug 2007 14:36:19 +0200, Bob Sanderson
<ne**@LUVSPAMbobsanderson.comwrote:
>This is my code:

if (file_exists($Fname))
> 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.php>
Table O.2. Wrapper SummaryAttribute 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()(HEAD 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.php>
<Bob Sanderson>
<Mon, 13 Aug 2007 12:36:19 GMT>
<Xn**********************************@69.28.186.15 8>
This is my code:

if (file_exists($Fname)) {
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="images/5005/5005001.pdf";

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

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

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

Aug 13 '07 #4
Rik
On Mon, 13 Aug 2007 15:34:27 +0200, Krustov <me@privacy.netwrote:
$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**@LUVSPAMbobsanderson.comwrote:
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.php>
<Rik>
<Mon, 13 Aug 2007 15:38:56 +0200>
<op.twz2u6xyqnv3q9@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.comwrote in news:op.twz2u6xyqnv3q9@metallium:
On Mon, 13 Aug 2007 15:34:27 +0200, Krustov <me@privacy.netwrote:
>$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.php>
<Rik>
<Mon, 13 Aug 2007 16:36:30 +0200>
<op.twz5i4ikqnv3q9@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.php>
<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
Rik
On Mon, 13 Aug 2007 17:02:17 +0200, Krustov <me@privacy.netwrote:
<comp.lang.php>
<Rik>
<Mon, 13 Aug 2007 16:36:30 +0200>
<op.twz5i4ikqnv3q9@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 .
And as usenet is part of internet, see my 'common sense' statement.
Usenet doesnt have any heirarcial command structure and everybody is
equal with everybody having the same rights .
'hierarchical', and people are encouraged to play nice. No rules does not
mean no self-censorship, and it doesn't mean nothing can be criticized. If
you can post code, which you can and may, I'm free to give my thoughts on
them. I might be a bit short and to the point, without much regard for
peoples feelings for their precious code, but none of my posts here are
aimed directly at a person, they're all about the code. Especially in a
topic opened by a starting PHP-user, good coding practices are something I
consider important. Future colleagues will be very happy with it.
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 .
I criticized your code, perfectly suitable in a PHP newsgroup. Don't post
code if you're not prepared for citicism. I did _not_ challenge your right
to post the code, I challenged to code itself, see the difference? If you
don't agree, tell me why, on a coding level, your way should be preferred.
I'm still open to a real conversation about that, I don't dictate
anything, but I would appreciate it if a difference in opinion over code
could be discussed without it getting personal.

Then again, I have no illusions about this thread being about PHP anymore,
f'upped to alt.flame
--
Rik Wasmus
Aug 13 '07 #11
<comp.lang.php>
<Rik>
<Mon, 13 Aug 2007 17:19:04 +0200>
<op.twz7h2h8qnv3q9@metallium>
I criticized your code, perfectly suitable in a PHP newsgroup. Don't post
code if you're not prepared for citicism
Is that in the newsgroup charter - or did you judge and jury that
particular rule yourself for your own use .

Understandable i suppose if you concider yourself to be a god .
Aug 13 '07 #12
<comp.lang.php>
<Rik>
<Mon, 13 Aug 2007 17:37:20 +0200>
<op.twz8citqqnv3q9@metallium>
You have not given any reason why your construct would be better
Wasnt aware i was obliged to explain myself to you for the heinous crime
of posting a couple of lines of code .
Aug 13 '07 #13
Krustov wrote:
<comp.lang.php>
<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 ? .
And a lot of other experienced programmers, yes.

You post poor code, be prepared to have it criticized.

And I agree with Rik - tell us WHY your code is better. It uses an
unnecessary extra variable, multiple tests where one would do, and
unnecessarily complicates the code.

Why is it better?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 13 '07 #14
<comp.lang.php>
<Jerry Stuckle>
<Mon, 13 Aug 2007 12:27:16 -0400>
<35******************************@comcast.com>
It uses an unnecessary extra variable
Your right of course - i will commit hari kari immediately .

Aug 13 '07 #15
On 13.08.2007 17:03 Krustov wrote:
<comp.lang.php>
<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 ? .
yes ;)

--
gosha bine

makrell ~ http://www.tagarga.com/blok/makrell
php done right ;) http://code.google.com/p/pihipi
Aug 13 '07 #16
<comp.lang.php>
<gosha bine>
<Mon, 13 Aug 2007 18:37:10 +0200>
<46***********************@read.cnntp.org>
makrell ~ http://www.tagarga.com/blok/makrell
Have you concidered using something like the following as all it needs
is class="makrell_background" put in the <bodytag .

..makrell_background
{
background-color: #FFFFFF;
background-image: url(images/header_fade.jpg);
background-repeat: repeat-x;
background-position: top;
}

You can see the effect on www.outerlimitsfan.co.uk and obviously you can
do a right click to get the image .

I like your clean web design and IMHO the above would enhance it
slightly by taking away 100% white look to it .


Aug 13 '07 #17
On 13.08.2007 18:55 Krustov wrote:
<comp.lang.php>
<gosha bine>
<Mon, 13 Aug 2007 18:37:10 +0200>
<46***********************@read.cnntp.org>
>makrell ~ http://www.tagarga.com/blok/makrell

Have you concidered using something like the following as all it needs
is class="makrell_background" put in the <bodytag .

.makrell_background
{
background-color: #FFFFFF;
background-image: url(images/header_fade.jpg);
background-repeat: repeat-x;
background-position: top;
}

You can see the effect on www.outerlimitsfan.co.uk and obviously you can
do a right click to get the image .

I like your clean web design and IMHO the above would enhance it
slightly by taking away 100% white look to it .
Thanks for the suggestion ;) I'll think about it.
--
gosha bine

makrell ~ http://www.tagarga.com/blok/makrell
php done right ;) http://code.google.com/p/pihipi
Aug 13 '07 #18
Krustov wrote:
i will commit hari kari immediately .
http://www.realultimatepower.net/ninja/seppuku.htm

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 54 days, 11:47.]

Fake Steve is Dead; Long Live Fake Bob!
http://tobyinkster.co.uk/blog/2007/08/13/fake-bob/
Aug 14 '07 #19

We do have a nice movie linked on our side explaining the file
handling in php - maybe this helps :)

http://www.skilltube.com/index.php?o...d=44&Itemid=52
On 13 Aug., 16:17, Bob Sanderson <n...@LUVSPAMbobsanderson.comwrote:
Rik <luiheidsgoe...@hotmail.comwrote innews:op.twz2u6xyqnv3q9@metallium:
On Mon, 13 Aug 2007 15:34:27 +0200, Krustov <m...@privacy.netwrote:
$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 15 '07 #20

We do have a nice movie linked on our side explaining the file
handling in php - maybe this helps :)

http://www.skilltube.com/index.php?o...d=44&Itemid=52
On 13 Aug., 16:17, Bob Sanderson <n...@LUVSPAMbobsanderson.comwrote:
Rik <luiheidsgoe...@hotmail.comwrote innews:op.twz2u6xyqnv3q9@metallium:
On Mon, 13 Aug 2007 15:34:27 +0200, Krustov <m...@privacy.netwrote:
$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 15 '07 #21

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

Similar topics

2
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. ...
10
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...
1
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:...
3
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...
5
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...
4
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...
6
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...
15
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...
3
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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...

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.