Allowing a .docx file to be uploaded?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tjstockton
Forum Newbie
Posts: 2
Joined: Sat Feb 06, 2010 2:51 pm

Allowing a .docx file to be uploaded?

Post by tjstockton »

Hello everyone, I'm new here. Hope I can get some help!! :)

I am working on some code for uploading specific types of files. I currently have successfully accounted for file types including .doc, .gif, .pdf, .tiff, .txt, .xls, and .xlsx. However, I am trying to allow for Microsoft Word 2007; this file extension is: .docx. I cannot seem to figure out the exact code I need, but here's what I have figured out thus far:

The following code (which is within an IF statement, where I'm specifying what types of files I am allowing) will allow .doc & .xls, but NOT .docx & .xlsx:
  • ($_FILES["file"]["type"] == "application/msword")
    ($_FILES["file"]["type"] == "application/vnd.ms-excel")
Since that does not allow .docx & .xlsx, I tried the following:
  • ($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
    ($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
Now, here's the problem. The code that I used to allow .xlsx DOES work, but the code to allow .docx WILL NOT work. Again, that code is:
  • ($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
Any ideas on why I am unable to successfully upload a .docx file? Any help will be greatly appreciated!

Thank you!!!!!

-tjstockton
tjstockton
Forum Newbie
Posts: 2
Joined: Sat Feb 06, 2010 2:51 pm

Re: Allowing a .docx file to be uploaded?

Post by tjstockton »

For the record, this issue has been resolved utilizing an array instead. Just took a different direction w/ the code, and honestly it's a lot more user-friendly for my Client anyway. This is snippet just to show how I went about a resolution:
  • $allowedExtensions = array("doc", "docx", "gif", "pdf", "rtf", "tiff", "txt", "xls", "xlsx"); //FILE EXTENSIONS ALLOWED TO BE UPLOADED
Thanks anyways! Maybe next time!

-tjstockton
Post Reply