/    Sign up×
Community /Pin to ProfileBookmark

Limited uploaded extensions

Hello, I have an upload form for my site where people can upload files for other people to see. I need to limit the extensions, so that people can only upload, for example: .zip files, .swf files, etc. I need to make it so that people can only upload those kinds and not other kinds of files. Can anyone help?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@bokehSep 11.2005 — So you are just going to do checking based on file extension?
Copy linkTweet thisAlerts:
@cobrasniper555authorSep 11.2005 — well...that and file size, but I got file size down, I just need to know how to do file extensions.
Copy linkTweet thisAlerts:
@NogDogSep 11.2005 — [code=php]
<?php
function file_type_allowed($file)
{
# define allowable file suffixes here (all lower case):
$typesAllowed = array("zip",
"swf",
"txt");
$parts = explode('.', $file);
# if there's a suffix and it's in the list, return true, else false
return((count($parts)<=1) ? FALSE :
in_array(strtolower(array_pop($parts)), $typesAllowed));
}
# test it:
$testData = array("file.txt",
"file.two.Zip",
"file3.SWF",
"file4",
"txt");
foreach($testData as $filename)
{
echo "<p>'$filename' is ";
echo (file_type_allowed($filename)) ? '' : 'not ';
echo "a valid file type.</p>n";
}
?>
[/code]
Copy linkTweet thisAlerts:
@cobrasniper555authorSep 11.2005 — Thanks NogDog!
×

Success!

Help @cobrasniper555 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...