New tutorials View all
Encapsulation in PHP
Abstract classes in PHP
An introduction to MySQL databases in PHP
Creating a user login and registration system.
First Lesson of HTML
New forum replies
Jim in MySQL Classdave101ua in MySQL ClassCodefreek in Music, what do you like?wescooldude3 in The big and general IRC...Jim in Currently listning to:Jim in Currently listning to:Jim in The big and general IRC Bot topic...
New frontpage replies
tutorials: Creating a user login and registration system.tutorials: Creating a user login and registration system.tutorials: Creating a user login and registration system.tutorials: Abstract classes in PHPtutorials: Abstract classes in PHP
New articles
New news
Snippet: Get the file extension
Posted as php on Wednesday 20 August 2008 23:25 by RealShadow
Replies on Get the file extension :
Description
Since we are posting snippets, it would be nice if I would have one too, right?
So this is a simple function I use to extract file extension in a cms for a <noname> webpage when user will upload a file.
I have added a check so you can see how it works then. For example, images.
Code (php)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
function get_extension($file) { $file = explode(".", $file); $file = array_reverse($file); $file = $file[0]; return $file; } $allowed = array ("jpg","gif","png"); if (!in_array(get_extension($file),$allowed)) { print 'Error message.'; } else { // rest of the code } |
Replies on Get the file extension :
Jump to comment page: 1
Jump to comment page: 1
You are not logged in. Please login or register an account, it just takes 30 seconds.

Nice one mate