homepage Welcome to WebmasterWorld Guest from 54.211.180.175
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
loop if statement
camilord




msg:4132488
 4:57 am on May 14, 2010 (gmt 0)

greetings...

i would like to ask if what is the shortcut code if something like;

<?php

function getFileExtension()
{
....
}

$filex = getFileExtension($_POST['file']);

$img = array('jpg','bmp','gif','png');

if ($filex = unknown_function($img))
{
...
}

?>

the unknown_function() is responsible to auto-validate the values in an array...

i encounter this in PHP website.. but can't find it now... i forgot the function name...

anybody?

 

Matthew1980




msg:4132531
 7:46 am on May 14, 2010 (gmt 0)

Hi there camilord,

Are you just trying to get the file extension, so that you can decide if it's 'allowed' or 'not allowed'?

Also is the function getfileextension() your own, I presume so as it's not a predefined function, the nearest is: [uk.php.net ]

The easiest way to get the filetype is this:-

//imagine as the string is filename.jpg
$fileExt = strip_tags(strtolower($_POST['your_file']));//clean and convert to lower case

//get filetype
$ext = strstr($fileExt, ".");
echo $ext;

This will echo .jpg - note: it includes the . Ok!

Could shove this into a function:-

Note that if its always from a $_POST or a $_GET you don't need to pass it into a function as it is a superglobal, so by definition the array (if set) is available throughout the scope of your project, ie: accesible anywhere ;)

//for a var
function FileExt($input){

$ext = strstr(strtolower(strip_tags($input)), ".");
return $ext;
}

//for a $_POST
function FileExt(){

$ext = strstr(strtolower(strip_tags($_POST['your_file'])), ".");
return $ext;
}

One last thing, I think that $_POST['file'] may be reserved for doing file uploads($_FILES[][]), but I could be wrong there.

Cheers,
MRb

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved