contentType for text documents?

D

darrel

I'm creating a file upload tool, and want to allow only DOC, XLS, PDF, RTF
or TXT files. I am using this to check:

if (contentType = "application/msword") _
or (contentType = "application/rtf") _
or (contentType = "application/ms-excel") _
or (contentType = "application/pdf") _
or (contentType = "application/txt") then

However, I'm not sure if that's the proper way...namly the 'msword' vs.
'ms-excel' (the two examples I found online).

Does the above look correct?

-Darrel
 
K

Kevin Spencer

How about just checking the file extension?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
D

darrel

How about just checking the file extension?

That's what I'm falling back on. Does changing the extension also change the
content-type? If so, then I guess it makes sense to just test for the file
extension.

I'm avoiding the 'hmm...my powerpoint file won't upload...Oh...I'll just
change the file extension...' issue.

-Darrel
 
K

Kevin Spencer

Okay, let's talk about Content type. It's an HTTP entity, that is, it is
used by internet web applications when sending a stream of data. It tells an
Intenet HTTP client what kind of file it is. However, although the client in
this case is sending the file, by the time your code gets to it, it's just a
file stream again. So, how does your OS determine what kind of file a file
is? It uses the file extension. So, how should you tell what kind of file it
is? Check the extension.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
D

darrel

Okay, let's talk about Content type. It's an HTTP entity, that is, it is
used by internet web applications when sending a stream of data. It tells an
Intenet HTTP client what kind of file it is. However, although the client in
this case is sending the file, by the time your code gets to it, it's just a
file stream again. So, how does your OS determine what kind of file a file
is? It uses the file extension. So, how should you tell what kind of file it
is? Check the extension.

Ah, so, what, exactly, is the point in grabbing the contentType if it simply
is based of the file extension?

Sounds like they are the same thing, at least when reading the file in.

-Darrel
 
K

Kevin Spencer

Ah, so, what, exactly, is the point in grabbing the contentType if it
simply
is based of the file extension?

I didn't say there WAS any point to doing that! There IS no point to it.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
D

darrel

I didn't say there WAS any point to doing that! There IS no point to it.

Good to know! Thanks.

-Darrel
 
B

Bruce Barker

when the browser uploads a file, it does not work hard to get a mime-type,
it usually sends, text, xml or binary (requires encoding). so you need to
check the file extension it supplies as it will be more accurate.

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,233
Latest member
AlyssaCrai

Latest Threads

Top