Re: File Ext

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



----- Original Message ----- 
From: "Svensson, B.A.T. (HKG)" <B.A.T.Svensson@lumc.nl>
> > I can\ only assume that it does work ok with a linux-based
> > webserver or it wouldn't be in there. In fact, if I put in is_file()
> > instead of !is_dir, it returns nothing at all.
>
> That code wont work on a unix based system since in many cases
> files does not have an exstensions at all, like executables and
> plain text files.

What I meant was the is_dir and is_file functions - they don't seem to
function at all on a windows box.

> If a file extension is present it is in most case only two
> characters long (.sh, .pl, .gz, .ps, etc).

I assumed - too much, perhaps - that the poster was using a windows machine
for this, given the content of his message.

> The file name convention with 8 + 3 chars is an old artifact
> remaining from DOS and Win3.x. The dot (not being the first
> character) does not carry any special mening as in DOS for
> windows. However if the dot is the first character of the
> file name under Unix, it means that the file should be
> "hidden", and this might casue a problem. Additional code
> would be needed to handle special cases like this.

I fully understand what the 8.3 naming convention is and where it comes
from... but despite it not being required anymore, it is still a very common
way of naming files (well, at least the .3 part).

> > checks to see if it's a directory or a file (theoretically...),
>
> On a unix based system you might find special files like pipes,
> links, block devices, and a lot of other "funny" files.

The is_dir function, obviously, will only grab regular directories
(according to the docs).  is_file only grabs regular files.  There is also
an is_link function.  As for the others... your guess is as good as mine, as
I am not a unix/linux person. :)

> I don't know how your code will react on this type of files,
> but one might like to test on special cases to find out.
>
> >extension.  Things it won't include that you might need:  files with a
> >4-character-or-more or a 2-character-or-less extension.  It only grabs
> >-character extensions.  From here, though, I think you can modify it to
> >o chatever it is you need done.
>
> This is fairly easy solved by scanning for a
> dot at the end of the file name and then cut
> out that part.
>
> Probaly strrpos() (note the dubble R's) will be
> easiet to use here. A generic code to extract the
> "tail" of a file name would then be:
>
> $pos = strrpos($FileName, "."); // Find the last occurence of a dot
> @FileExtension = "";
> if (@pos) {
>    @FileExtension = substr($FileName, $pos);
> }

I knew there had to be someone who knew a much better way than I'd put out
there, but I still figured I'd toss something out for the person who asked.
:)  I certainly don't consider myself an "expert" (as, from previous posts
I've read from you indicate, you are) when it comes to php programming, but
I do like to try.  Thanks for the improvement, B.A.T.

(V)

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux