RE: File Ext

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

 



> 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.

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

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.


> 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.

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);  
}




----- Original Message ----- 
From: "Dean Hayes" <wizard_guy@hotmail.com>
> Hey,
>
> I need to be able to find out what the file ext is on all files within
the
> dir i am reading. I am searched the php manual and i can not find
anything
> that does this does anyone know of a way i can and print it out.

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

-- 
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