Topic awaiting preservation: file updload mime types |
|
---|---|
Author | Thread |
Paranoid (IV) Inmate From: 1393 |
posted 02-20-2006 17:47
I've got a php upload script I've created and I want to restrict all file types except for pdf, gif and jpg. I've been reading up on mime types but it seems that it is totally browser dependant (like AOL doesn't send proper mime types ect.). How do I go about this properly? |
Nervous Wreck (II) Inmate From: Stockholm, Sweden |
posted 02-20-2006 18:37
I'm using this following code. As far as I know it works well on both PC and Mac. IE and FF and all the rest. code: $FILE_MIMES = array('image/jpeg','image/jpg','image/gif','image/png'); $FILE_EXTS = array('.jpeg','.jpg','.png','.gif'); if (!in_array($file_type, $FILE_MIMES) && !in_array($file_ext, $FILE_EXTS) ) echo = "Sorry, $file_name($file_type) was not allowed to be uploaded.";
|
Paranoid (IV) Inmate From: New Jersey, USA |
posted 02-20-2006 18:37
You can do an eregi on the file name. Something like: code: if (!eregi('.pdf', $filename) || !eregi('.gif', $filename) || !eregi('.jpe?g', $filename)) { //put code to refuse the upload here } else { //handle the upload here }
|
Paranoid (IV) Mad Scientist From: Omicron Persei 8 |
posted 02-20-2006 18:48 |
Nervous Wreck (II) Inmate From: |
posted 02-21-2006 07:22
MIME Filetype is a lot harder to spoof than extensions, so it's best imo to use both. |
Maniac (V) Mad Scientist with Finglongers From: Germany |
posted 02-21-2006 08:48
You don't listen to the mime types the client sends. |
Nervous Wreck (II) Inmate From: |
posted 02-22-2006 03:50
I said it was harder, TP, not that it wasn't possible. I agree it wouldn't be hard to spoof the mime-type (writing raw http headers is not rocket science), but it's of a completely different degree from changing the file extension. =) |
Maniac (V) Mad Scientist with Finglongers From: Germany |
posted 02-22-2006 08:32
well... betting that an attacker ist stupid is a sure way to loose money. |
Maniac (V) Inmate From: Sthlm, Sweden |
posted 02-22-2006 08:57
quote:
|