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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:00:06+00:00 2026-05-22T15:00:06+00:00

Unable to detect mime type. if I remove ($mime==image/jpeg || $mime==image/pjpeg) , it could

  • 0

Unable to detect mime type. if I remove ($mime=="image/jpeg" || $mime=="image/pjpeg"), it could upload the image successfully.

$mime = $_FILES['Filedata']['type'];
if((!empty($_FILES['Filedata']['tmp_name'])) && ($_FILES['Filedata']['error'] == 0)) {
  $filename = basename($_FILES['Filedata']['name']);
  $ext = pathinfo($filename, PATHINFO_EXTENSION);
  if (($ext=="jpg" || $ext=="jpeg") && ($mime=="image/jpeg" || $mime=="image/pjpeg") && ($_FILES["Filedata"]["size"] < 350000)) {
        $newname = $filename;
        if (!file_exists($newname)) {
            if (move_uploaded_file($_FILES['Filedata']['tmp_name'], "./photo/" . $newname)) {
                echo "It's done! The file has been saved as: ".$newname;
            } else {
                echo "Error: A problem occurred during file upload!";
            }
        } else {echo "Error: File ".$_FILES["uploaded_file"]["name"]." already exists";}
  } else {
     echo "Error: Only .jpg images under 350Kb are accepted for upload";
  }
} else {
    echo "Error: No file uploaded";
}
  • 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-22T15:00:06+00:00Added an answer on May 22, 2026 at 3:00 pm

    The name and type information for uploaded files should be seen as purely informational and never be used for anything serious, since it’s user supplied information and can easily be spoofed. You should only ever look at the tmp_name, error and size fields to determine if you want to accept a file. To find the actual MIME type of a file, use PHP’s built-in functions:

    if ($file['error'] == UPLOAD_ERR_NO_FILE) {
        die('No file uploaded');
    }
    
    if ($file['error'] != UPLOAD_ERR_OK) {
        die('Error during upload');
    }
    
    if (!$file['size'] || !is_uploaded_file($file['tmp_name'])) {
        die('File is weird');
    }
    
    $extensions = array(IMAGETYPE_GIF => '.gif', IMAGETYPE_JPEG => '.jpg', IMAGETYPE_PNG => '.png');
    $exifType = exif_imagetype($file['tmp_name']);
    if (!isset($extensions[$exifType])) {
        die('Unsupported file type');
    }
    
    $ext = $extensions[$exifType];
    $targetDir = '/somewhere/else/';
    
    do {
        $target = $targetDir . uniqid() . $ext;
    } while (file_exists($target));
    
    if (!move_uploaded_file($file['tmp_name'], $target)) {
        die('Something went wrong');
    }
    
    echo 'Yay, uploaded!';
    

    Not that you should necessarily use that many die() statements though, that’s just for demonstration purposes.

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

Sidebar

Related Questions

I am unable to detect when input type=file changes its value after user selects
Unable to cast object type System.Collections.Generic.List 1[NorthwindMVC3.Models.Product] to the type ofSystem.Collections.Generic.IEnumerator 1[NorthwindMVC3.Models.Product].\ public IEnumerator<Product>
I am unable to detect the error in the following C++ program. The code
I am using TextWatcher and I am unable to detect Backspace key in TextWatcher.afterTextChange
I am using zbar to scan barcodes from images. Zbar is unable to detect
I'm unable to detect the cause of error. Please help point me out and
I am unable to detect what is outgoing number, its always giving me null
Currently with WMI's Win32_Process, I seem unable to detect if a batch file is
I'm animating a couple of views with animateWithDuration: and i'm simply unable to detect
I'm using a lot of javascript here and am unable to detect the problem

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.