file_exists does not work
file_exists does not work
am 13.08.2007 14:36:19 von Bob Sanderson
This is my code:
if (file_exists($Fname)) {
echo "
$Fname exists | ";
} else {
echo "$Fname does not exist | ";
}
$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.
Re: file_exists does not work
am 13.08.2007 14:42:06 von luiheidsgoeroe
On Mon, 13 Aug 2007 14:36:19 +0200, Bob Sanderson
wrote:
> 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:
:
"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:
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
Re: file_exists does not work
am 13.08.2007 14:59:07 von Bob Sanderson
Rik wrote in
news:op.twzz8gznqnv3q9@metallium:
> On Mon, 13 Aug 2007 14:36:19 +0200, Bob Sanderson
> wrote:
>
>> 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:
> :
> "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:
>
> 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?
Re: file_exists does not work
am 13.08.2007 15:00:28 von unknown
Post removed (X-No-Archive: yes)
Re: file_exists does not work
am 13.08.2007 15:23:07 von alvaro.NOSPAMTHANKS
Bob Sanderson escribió:
> 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?
You're trying to find out whether a URL points to a valid resource
without actually fetching the file. Are you sure that's what you really
need? If you just need to get a file from you own server you don't need
to play with HTTP: feed file_exists() with a file system path:
$file=$_SERVER['DOCUMENT_ROOT'].'/images/dwg_images/5005/500 5001_.pdf';
if( file_exists($file) ){
// Whatever
}
--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor austrohúngaro: http://www.demogracia.com
--
Re: file_exists does not work
am 13.08.2007 15:34:27 von Hans-Peter Sauer
> This is my code:
>
> if (file_exists($Fname)) {
> echo "$Fname exists | ";
> } else {
> echo "$Fname does not exist | ";
> }
>
> $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 "$tempname FILE NOT FOUND | ";}
if ($pass==1) {print "$tempname OK | ";}
Re: file_exists does not work
am 13.08.2007 15:38:56 von luiheidsgoeroe
On Mon, 13 Aug 2007 15:34:27 +0200, Krustov wrote:
> $pass=3D1;
> if (!file_exists($tempname)) {$pass=3D0;}
> 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
Re: file_exists does not work
am 13.08.2007 15:49:14 von luiheidsgoeroe
On Mon, 13 Aug 2007 14:59:07 +0200, Bob Sanderson
wrote:
> 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
, several options for determining wether
an URL can be 'found' are given there.
--
Rik Wasmus
Re: file_exists does not work
am 13.08.2007 15:51:28 von Hans-Peter Sauer
> > $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 .
[OT: conditional statements] Re: file_exists does not work
am 13.08.2007 16:00:17 von luiheidsgoeroe
On Mon, 13 Aug 2007 15:51:28 +0200, Krustov wrote:
>
>
>
>
>
>> > $pass=3D1;
>> > if (!file_exists($tempname)) {$pass=3D0;}
>> > 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 variable=
s
>> popping up in your script if you don't need them, and avoid
>> double/repeated comparisons...
>>
>
> Up your arse .
Why, thank you. That is exactly what you say to other coders that might =
=
work on the same project with this kind of code.
> I dont recall asking you for your zen like wisdom on how i should or
> shouldnt write code.
Neither did the OP ask for lousy coding practises. Several people allrea=
dy =
told him he should try the local filesystem, the only thing you added wa=
s =
cumbersome code most of us would be ashamed to have in our scripts. What=
=
was _your_ reasoning for posting this enlightened code?
-- =
Rik Wasmus
Re: file_exists does not work
am 13.08.2007 16:17:31 von Bob Sanderson
Rik wrote in news:op.twz2u6xyqnv3q9@metallium:
> On Mon, 13 Aug 2007 15:34:27 +0200, Krustov 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.
Re: [OT: conditional statements] Re: file_exists does not work
am 13.08.2007 16:25:26 von Hans-Peter Sauer
> > I dont recall asking you for your zen like wisdom on how i should or
> > shouldnt write code.
>
> Neither did the OP ask for lousy coding practises. Several people allready
> told him he should try the local filesystem, the only thing you added was
> cumbersome code most of us would be ashamed to have in our scripts. What
> was _your_ reasoning for posting this enlightened code?
>
I'm unaware of the newsgroup rules on CLP .
In future - and before posting any more code snippets - i will stop to
concider if the php code will pass or fail your rigorous vetting and
validation procedures .
Re: [OT: conditional statements] Re: file_exists does not work
am 13.08.2007 16:36:30 von luiheidsgoeroe
On Mon, 13 Aug 2007 16:25:26 +0200, Krustov wrote:
>
>
>
>
>
>> > I dont recall asking you for your zen like wisdom on how i should or
>> > shouldnt write code.
>>
>> Neither did the OP ask for lousy coding practises. Several people
>> allready
>> told him he should try the local filesystem, the only thing you added
>> was
>> cumbersome code most of us would be ashamed to have in our scripts. What
>> was _your_ reasoning for posting this enlightened code?
>>
>
> I'm unaware of the newsgroup rules on CLP .
Common mistake: there are very little rules, but as it is internet, people
tend to forget to use common sense...
> In future - and before posting any more code snippets - i will stop to
> concider if the php code will pass or fail your rigorous vetting and
> validation procedures .
By all means, continue posting code snippets, especially when you've got
something _new_ to say. Usenet is a collaboration by nature. If I think
it's flawed somewhere, I'm always happy to supply constructive critisism.
Wether you indeed take it as constructive, or you have a to sensitive ego
to see that is up to the reader. Feel free to enter into a _real_
discussion that doesn't start with 'up your arse', or killfile me if you
cannot take it.
--
Rik Wasmus
Re: [OT: conditional statements] Re: file_exists does not work
am 13.08.2007 16:58:22 von Jerry Stuckle
Krustov wrote:
>
>
>
>
>
>>> I dont recall asking you for your zen like wisdom on how i should or
>>> shouldnt write code.
>> Neither did the OP ask for lousy coding practises. Several people allready
>> told him he should try the local filesystem, the only thing you added was
>> cumbersome code most of us would be ashamed to have in our scripts. What
>> was _your_ reasoning for posting this enlightened code?
>>
>
> I'm unaware of the newsgroup rules on CLP .
>
> In future - and before posting any more code snippets - i will stop to
> concider if the php code will pass or fail your rigorous vetting and
> validation procedures .
Rik is correct. When you post sample code, you should try to ensure it
is a good example. Yours could have used a lot of improvement.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: [OT: conditional statements] Re: file_exists does not work
am 13.08.2007 17:02:17 von Hans-Peter Sauer
> 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 .
Re: [OT: conditional statements] Re: file_exists does not work
am 13.08.2007 17:03:58 von Hans-Peter Sauer
<8ImdnYFtKYZP7F3bnZ2dnUVZ_szinZ2d@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 ? .
Re: [OT: conditional statements] Re: file_exists does not work
am 13.08.2007 17:19:04 von luiheidsgoeroe
On Mon, 13 Aug 2007 17:02:17 +0200, Krustov wrote:
>
>
>
>
>
>> 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
Re: [OT: conditional statements] Re: file_exists does not work
am 13.08.2007 17:27:57 von Hans-Peter Sauer
> 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 .
Re: [OT: conditional statements] Re: file_exists does not work
am 13.08.2007 17:37:20 von luiheidsgoeroe
On Mon, 13 Aug 2007 17:27:57 +0200, Krustov wrote:
>
>
>
>
>
>> 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 .
It is comp.lang.php isn't it? What would we talk about here if not
PHP(-code)?
> Understandable i suppose if you concider yourself to be a god .
You keep accusing me of something I am not doing. You seem unable to
discuss the very point this runaway thread started on, the cumbersome
conditional statement. If anyone is to be accused of a god-complex it is
you, who cannot take criticism. I've made mistakes in my PHP scripts in
the past and undoubtly will in the future. When someone points out to me
how my code could be better I'd rather not blame them.
You have not given any reason why your construct would be better, and I
doubt you
will. So, this will be my last reply to you that's not PHP related.
It has been fun, have a nice day.
--
Rik Wasmus
Re: [OT: conditional statements] Re: file_exists does not work
am 13.08.2007 18:11:53 von Hans-Peter Sauer
> 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 .
Re: [OT: conditional statements] Re: file_exists does not work
am 13.08.2007 18:27:16 von Jerry Stuckle
Krustov wrote:
>
>
>
> <8ImdnYFtKYZP7F3bnZ2dnUVZ_szinZ2d@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.
jstucklex@attglobal.net
==================
Re: [OT: conditional statements] Re: file_exists does not work
am 13.08.2007 18:32:46 von Hans-Peter Sauer
<35OdncUPYvU1G13bnZ2dnUVZ_sjinZ2d@comcast.com>
> It uses an unnecessary extra variable
>
Your right of course - i will commit hari kari immediately .
Re: [OT: conditional statements] Re: file_exists does not work
am 13.08.2007 18:37:10 von gosha bine
On 13.08.2007 17:03 Krustov wrote:
>
>
>
> <8ImdnYFtKYZP7F3bnZ2dnUVZ_szinZ2d@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
Re: [OT: conditional statements] Re: file_exists does not work
am 13.08.2007 18:55:05 von Hans-Peter Sauer
<46c088d0$0$11220$6e1ede2f@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 tag .
..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 .
Re: [OT: conditional statements] Re: file_exists does not work
am 13.08.2007 19:04:01 von gosha bine
On 13.08.2007 18:55 Krustov wrote:
>
>
>
> <46c088d0$0$11220$6e1ede2f@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 tag .
>
> .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
Re: [OT: conditional statements] Re: file_exists does not work
am 14.08.2007 10:08:06 von Toby A Inkster
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/
Re: file_exists does not work
am 15.08.2007 14:34:14 von lists73
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?option=com_content&task=v iew&id=44&Itemid=52
On 13 Aug., 16:17, Bob Sanderson wrote:
> Rik wrote innews:op.twz2u6xyqnv3q9@metallium:
>
> > On Mon, 13 Aug 2007 15:34:27 +0200, Krustov 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.
Re: file_exists does not work
am 15.08.2007 14:34:26 von lists73
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?option=com_content&task=v iew&id=44&Itemid=52
On 13 Aug., 16:17, Bob Sanderson wrote:
> Rik wrote innews:op.twz2u6xyqnv3q9@metallium:
>
> > On Mon, 13 Aug 2007 15:34:27 +0200, Krustov 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.