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

  • Home
  • SEARCH
  • 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 877391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:36:02+00:00 2026-05-15T11:36:02+00:00

How do I retrieve the content-type of a file using PHP? I don’t want

  • 0

How do I retrieve the content-type of a file using PHP?

I don’t want to rely on the file extension alone.

Thanks!

  • 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-15T11:36:03+00:00Added an answer on May 15, 2026 at 11:36 am

    Because files themselves don’t necessarily store the mime-type, you have to use a variety of methods to get hints to what the correct type is. If you know the file is an image, use http://www.php.net/manual/en/function.getimagesize.php … and you can check if a .doc or .xsl “looks like” what the extension claims it to be, because those file types always start with the same set of bytes http://filext.com/file-extension/DOC (see “identifying characters”). In some cases it would be very difficult to determine without relying on an extension (for instance what’s the difference between text/plain and text/css apart from the .css, unless you were to parse the file and account for every possible text type?)

    In the end, the more you know about the file types you’re interested in, the more you can use that to verify a file to be of that type, and the more you spend writing code to do that job, the better the chances of you determining the correct mime-type!

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

Sidebar

Related Questions

If I goto http://site.com/uploads/file.pdf I can retrieve a file. However, if I have a
I need to retrieve the PIN from a notepad file (below) and check it
I have a file on my computer that I wanted to copy into a
I'm using ASP.NET 4, EF 4 and FILESTREAM in SQL 2008 to add/read files
I'm a javascript guy getting too deep into php (even though this question is
The project I'm working on allows an end-user to modify CSS code to integrate
I am trying to create my own functions in the subclass of BaseHTTPRequestHandler as
UPDATE: Solved via: append = append+'/output/'+output; var url = '/producer/json/index/period/'+period+'/empties/'+empties+'/movies/'+movies+'/fields/'+fields+'/start/'+start+'/end/'+end+append+''; $.ajax({ url: ''+url+'', success:
I have a function from which I would like to return a value as
i wish to send some data as array from my iphone app to server

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.