homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Check if file type is valid

 4:30 pm on Apr 20, 2007 (gmt 0)

I'm uploading files onto my site and I need to determine if the extension is one from the following array, AND determine the filetype using the same array.

$validTypes = array(
"app" => array("jad", "jar", "mpn"),
"img" => array("gif", "jpg", "jpeg", "png", "thm", "tif", "tiff"),
"snd" => array("aac", "amr", "mid", "mmf", "mp3"),
"txt" => array("ini", "nfo", "txt"),
"vid" => array("3g2", "3gp", "mp4", "mpg")

The question is, how do I traverse this array and return:
- If the extension was found on list
- What type (app, img, snd...) was the file

Thanks in advance. I totally suck with arrays on PHP!



 6:09 pm on Apr 20, 2007 (gmt 0)

You've set up $validTypes as an array of arrays, so you need to check the extension against each of the arrays in it.
$found = false;
foreach($validTypes as $type_name => $type_array) {
$found = true;
} // EndIf found type
} // EndForEach allowed type
if($found) {
echo 'Type is' . $type_name;
} // EndIf it was in list
else {
echo 'Uploaded file type not found';
} // EndElse didn't find it


 7:16 pm on Apr 20, 2007 (gmt 0)

Thank you very much, that worked perfectly. It could have taken me days to figure that out.

Thanks again.

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