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 4042376
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:59:51+00:00 2026-05-20T12:59:51+00:00

I am working on a PHP upload script which allows uploading only PDF files.

  • 0

I am working on a PHP upload script which allows uploading only PDF files. I am checking for the application/pdf MIME type before uploading. I have a PDF from my client that I am testing the upload script with and it is failing the upload error check and telling me that the file is a MIME type of application/download. I did download the PDF from the client via GMail. I also tested this with a PDF that I created in Photoshop and the script tells me that it is also of application/download type.

Here is how I am checking:

$mimeType = 'application/pdf';

if($_FILES[$filesName]['type'] != $mimeType)
{
  throw new UploadErrorException('File is not of correct type.');
}

I am trying to get the Fileinfo extension installed on my server (per grunk’s advice), but for now I am looking for something to work without it.

Any ideas? 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-20T12:59:52+00:00Added an answer on May 20, 2026 at 12:59 pm

    Your upload script allows any file type as long as the client says it’s PDF. Some browsers can not determine MIME types (duh, since determining MIME types is a hard problem) and just send a generic one. The correct way to check for the “real” MIME type is to use fileinfo.

    If you don’t have fileinfo, use the following drop-in replacement (PDF only):

    if (!class_exists('finfo')) {
      class finfo {
         function buffer($string) {
           switch (substr($string, 0, 4)) {
           case '%PDF': return 'application/pdf';
           default: return 'application/binary';
           }
         }
         function file($file_name, $options=0, $context=NULL) {
           $f = fopen($file_name, 'rb', false, $context);
           if ($f === false) return false;
           $magic = fread($f, 4);
           fclose($f);
           return $this->buffer($magic);
        }
      }
    }
    $finfo = new finfo();
    echo $finfo->file('test.pdf');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a PHP upload script and when testing my error checks,
Okay so im working on this php image upload system but for some reason
I'm working on a PHP application that links into the Protx VSP Direct payment
I am working on a PHP application that intends to ease company workflow and
Hey everyone, I'm working on a PHP application that needs to parse a .tpl
Dear friends, this is a script which simply upload file and insert filename into
If you are working in PHP (or I guess any programming language) and using
I'm used to working with PHP but lately I've been working with Java and
I am a web-developer working in PHP. I have some limited experience with using
I'm working on a PHP CMS like project and I'm trying to find out

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.