/    Sign up×
Community /Pin to ProfileBookmark

limiting file types

OMG how many ways is there to do this and which do you guys feel is the most efficiant and effective!! i need to limit them to .wma and .jpg

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@aussie_girlJul 11.2006 — OMG how many ways is there to do this and which do you guys feel is the most efficiant and effective!! i need to limit them to .wma and .jpg[/QUOTE]

[code=php]
$allowed = array ('image/jpeg', 'image/jpg', 'image/pjpeg');
if (in_array($_FILES['upload']['type'], $allowed))
{
// Move the file to the correct directory..else error message
//Not sure about the wma, but this is for images
[/code]
Copy linkTweet thisAlerts:
@NogDogJul 11.2006 — Note that, as per http://us2.php.net/manual/en/features.file-upload.php ...
$_FILES['userfile']['type']

The mime type of the file, if the browser provided this information. An example would be "image/gif". This mime type is however not checked on the PHP side and therefore don't take its value for granted. [/quote]
Therefore, if you're concerned about users "sneaking" invalid file types in, simply checking the type as above or checking the file name's suffix will not be sufficient. You would actually need to read the header information from the file to determine what type it really is. For image files, this can be done with the [url=http://www.php.net/exif_imagetype]exif_imagetype() function[/url]. I don't know if there's anything similar for .wma files.
Copy linkTweet thisAlerts:
@bokehJul 11.2006 — OMG how many ways is there to do this and which do you guys feel is the most efficiant and effective!! i need to limit them to .wma and .jpg[/QUOTE]Are you talking about limiting uploads? Or something else? Your question doesn't explain too well.
Copy linkTweet thisAlerts:
@mikeflyauthorJul 12.2006 — yes file types on upload's
Copy linkTweet thisAlerts:
@bokehJul 12.2006 — well getimagesize() returns false if a file is not an image. For certain other files that follow a strict format it is possible to access the first few bytes of the file and see if they correspond with the file format.
×

Success!

Help @mikefly 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.19,
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,
)...