/    Sign up×
Community /Pin to ProfileBookmark

MIME problem

Hi,

I can’t seem to find any manuals on php.net that shows how can I validate a file upload by checking its MIME type. I used the

[code=php]explode(‘.’, $filename);[/code]

method on handling my file upload validation (which I positively believe is not guaranteed). Can someone show me some snippet on such matters?

Thank you so much.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@scragarMar 31.2011 — Mimetypes can still be faked, it would not add drastically to your security. Much better to make sure any attempts to put anything nasty in a file does nothing(never use include for files uploaded, and where possible prevent execution using. htaccess).
Copy linkTweet thisAlerts:
@NoasITMar 31.2011 — Using your explode method, assuming your setting it to an array make sure you check the last array entry, since someone could upload a file such as picture.of.me.jpg The explode method is what I used for my image uploads, then I created an array of acceptable extensions and searched that array for the extension I extracted, if successful proceed with upload, if not end upload display error.
×

Success!

Help @kingdm 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.18,
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,
)...