/    Sign up×
Community /Pin to ProfileBookmark

php check file type?

ok, ive been trying to figure this out, what can i use to run a basic check to see if something is a specific file type? say for example i only want to allow “.doc” file types. ill keep looking but any assistance would be nice

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@bathurst_guyMar 01.2006 — Is this on an upload?

You could check that the $_FILES['userfile']['type'] has a mime of a word doc
Copy linkTweet thisAlerts:
@welshauthorMar 01.2006 — yes, how would i do that, right now its checking for an image, the line is:
[code=php]
@getimagesize($_FILES[$fieldname]['tmp_name'])
or error('only image uploads are allowed', $uploadForm);
[/code]
Copy linkTweet thisAlerts:
@bathurst_guyMar 01.2006 — [code=php]if($_FILES[$fieldname]['type'] == "application/msword"){
#upload it
}else{
error("Incorrect file type. Only Microsoft word documents can be uploaded");
}[/code]
Copy linkTweet thisAlerts:
@welshauthorMar 01.2006 — k, and to do multiple file types it would be:
[code=php]
if($_FILES[$fieldname]['type'] == "application/msword" or "image/jpeg"){
#upload it
}else{
error("Incorrect file type. Only Microsoft word documents can be uploaded");
}
[/code]

am i remotely close?
Copy linkTweet thisAlerts:
@bathurst_guyMar 01.2006 — [code=php]if($_FILES[$fieldname]['type'] == "application/msword" ||

$_FILES[$fieldname]['type'] == "image/jpeg"){ [/code]
Copy linkTweet thisAlerts:
@welshauthorMar 01.2006 — ok, thanks alot.
×

Success!

Help @welsh 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.6,
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,
)...