--- Russell Curtis <[EMAIL PROTECTED]> wrote:
> I'm trying to use the split function to identify the
> extension of an
> uploaded file:
> 
>    $file_name = $_FILES['userfile']['name'];
>    $pieces = explode(".", $file_name);
>    $file_extension = $pieces[1]; // piece2
> 
> Which will work, providing that the uploaded file
> only has one full-stop in
> the name (so 'thisfile.pdf' will return 'pdf' as the
> $file_extension, for
> example.)
> 
> However, there is a chance that someone will try and
> upload a file which has
> more than one full-stop in it (eg. 'this.file.pdf')
> which will of course
> return 'file' as the variable $file_extension.
> 
> My question is, is there any way to determine what
> the *last* result of the
> array is rather than working from the first?
> 
> This may be a basic question, but I'm a newbie;
> apologies in advance if this
> is a simple one. I'm using PHP4, BTW, if that makes
> a difference.

Hi, 

This should do your work.


$fileex=explode(".",$filename);
if(count($fileex)==2)
{
$fileextension=$fileex[1];
}else 
{
$fileextension=$fileex[count($fileex)-1];
}


zareef ahmed 

> 
> Cheers
> 
> Russell
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 


=====
Zareef Ahmed :: A PHP Developer in Delhi(India).
Homepage :: http://www.zasaifi.com


                
__________________________________
Do you Yahoo!?
Read only the mail you want - Yahoo! Mail SpamGuard.
http://promotions.yahoo.com/new_mail 

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

Reply via email to