Using split to establish extension of file

From: Date: Wed, 07 Jul 2004 10:24:24 +0000
Subject: Using split to establish extension of file
Groups: php.general 
Request: Send a blank email to php-general+get-189854@lists.php.net to get a copy of this message
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. Cheers Russell

« previous php.general (#189854) next »