Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7042651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:11:39+00:00 2026-05-28T02:11:39+00:00

I’m uploading some files. Below is part of the script for the upload (I’m

  • 0

I’m uploading some files. Below is part of the script for the upload (I’m using codes from https://github.com/blueimp/jQuery-File-Upload/blob/master/php/index.php)

$upload = isset($_FILES[$this->options['param_name']]) ?
                $_FILES[$this->options['param_name']] : null;
$info = array();
if ($upload && is_array($upload['tmp_name'])) {
    foreach ($upload['tmp_name'] as $index => $value) {
    $info[] = $this->handle_file_upload(
    $upload['tmp_name'][$index],
            isset($_SERVER['HTTP_X_FILE_NAME']) ?
                  $_SERVER['HTTP_X_FILE_NAME'] : $upload['name'][$index],
            isset($_SERVER['HTTP_X_FILE_SIZE']) ?
                  $_SERVER['HTTP_X_FILE_SIZE'] : $upload['size'][$index],
            isset($_SERVER['HTTP_X_FILE_TYPE']) ?
                  $_SERVER['HTTP_X_FILE_TYPE'] : $upload['type'][$index],
                   $upload['error'][$index]
     );
}

When checked, the mime type through $_SERVER['HTTP_X_FILE_TYPE'] or $upload['type'][$index] returns application/vnd.openxmlformats-officedocument.presentationml.presentation, application/vnd.openxmlformats-officedocument.wordprocessingml.document for pptx, docx files respectively.

Now after completing the upload, I’m trying to display the files and I’m using finfo_file() to get the mime type.

$mime_type = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $file_path);
echo $mime_type;

For images files (like png, jpeg) & pdf, the type returns as expected but for the pptx and docx files, the mime type returned is application/zip.

Why is it not returning the same as while in uploading? Is there something wrong with my code or should I expect this? How do I decide which file type it is then?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:11:40+00:00Added an answer on May 28, 2026 at 2:11 am

    The same file can have different and mulitple mime-types, that is totally normal.

    Additionally the mime-type is only meta-information next to the file itself. Theoretically you can give any file any mime-type. That would not be very useful, but it works. It’s just a concept.

    The finfo library will try to obtain the mime-type of a file “magically” by looking into the file trying to identify the format. Then it will return the mime-type according to it’s database.

    Why is it not returning the same as while in uploading?

    The mime-type within the request is given by the HTTP client. It might guess as well, but often it takes the value from information the underlying operating system is giving for that file.

    As you can see with your issue that the more common the file-type is, the better it will match (the images).

    However as pptx and docx files are actually zip-files, the finfo library will identify those as application/zip because the headers of those files (magic numbers) show that it is technically a zip file.

    Is there something wrong with my code or should I expect this?

    You should not expect that the mime-type of finfo matches the request header mime-type. Those are two different things.

    How do I decide which file type it is then?

    That depends. You can decide to trust the http header, you can decide to trust finfo, you can decide to compare the file extensions as well and a combination of all three.

    Additionally you can decide to even add more. This entirely depends on what you do with the uploaded file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.