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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:46:04+00:00 2026-06-03T01:46:04+00:00

I am on shared hosting, and have been battling with them to get fileinfo

  • 0

I am on shared hosting, and have been battling with them to get fileinfo working, we have finally got it working, but again I have been hit with another barrier, I have essentially got this because I am creating a new file upload tool and we need to know what mimetypes are being uploaded, but fileinfo does not want to play ball.

So, a .sql file will return text/plain, correct.

However, every other file will simply return application/octet-stream, what I am wondering is why this is the case, I don’t want to be pissing the host off with tons of questions so I want to get some research on the issue before I hassle them furthur.

Code:

function get_mime($filename)
{
    $result = new finfo(FILEINFO_MIME_TYPE, "/usr/share/file/magic.mime"); 
    return $result->file($filename, FILEINFO_MIME_TYPE);
}

echo $user->get_mime($_FILES['file']['tmp_name'][$i]);

Any help would be greatly appreciated, many thanks

Update

So I have gone about updating the code of the MIMETYPE check, and I have updated the code to reflect the following(for the function):

function get_mime($filename)
{
    $result = new finfo(FILEINFO_MIME_TYPE, "/usr/share/file/magic.mime"); // return mime type ala mimetype extension

    if (is_resource($result) === true)
    {
        return $result->file($filename, FILEINFO_MIME_TYPE);
    } else {
        return "failed";
    }

    return false;
}

Obviously, as you can see I have made it output failed when it, fails. This is happening 100% of the time, and removing that if statement causes it to return application/octet-stream, which is incorrect.

The upload process will be: User uploads -> Files are moved to a temporary folder above public, (upload_check) where they will be checked by fileinfo, if the file is not what we accept it will be discarded, else it will be copied to the public files and and then discarded from the temporary folder.

I have created that process, and still fileinfo doesn’t want to co-operate and returns application/octet-stream for everything, even though they are on the server just saved above the public_html folder.

Any advice?

Jake

  • 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-06-03T01:46:06+00:00Added an answer on June 3, 2026 at 1:46 am

    Advice

    I really think you are getting things wrong here …

    A. when a file is uploaded it also returns mime type automatically in the $_FILES

    echo $_FILES['file']['type'][$i] ;
    

    B if you want to get mime for a file that was not uploaded, or try and make a better determination that what the client headers provided, use mime_content_type http://php.net/manual/en/function.mime-content-type.php

    echo mime_content_type($fileName);
    

    C. Depreciation

    Both mime_content_type & Fileinfo are not properly maintained and they have been depreciated.

    Update: It once was incorrectly marked as deprecated in the manual, but it has been fixed https://bugs.php.net/bug.php?id=71367 on the 14th of January 2016. As can see supports 7.0 so not discontinued at all.

    Alternatively can suggest you look at the following links for replacement

    Getting mime type of zipped files

    http://www.php.net/manual/en/function.mime-content-type.php#87856

    D. You can also use getID3 http://sourceforge.net/projects/getid3/files/getID3%28%29%201.x/1.9.3/ which can check the real mime type for some common files …

    E. Using Linux Command line probably saver

    $mime = shell_exec("file -bi " . escapeshellarg($file));   
    

    Or on Mac

    $mime = shell_exec("file -b --mime ".escapeshellarg($file));
    

    Finally

    Why do you want to work on $_FILES['file']['tmp_name'][$i] directly ?? This has been know to give so many issues

    try

    $tempDir = ""; // Temp
    foreach ( $_FILES ["file"] ["error"] as $key => $error ) {
        if ($error == UPLOAD_ERR_OK) {
            $tmp_name = $_FILES ["file"] ["tmp_name"] [$key];
            $name = $_FILES ["file"] ["name"] [$key];
            $tempFile = "$tempDir/$name";
            move_uploaded_file ( $tmp_name, $tempFile );
            echo $user->get_mime ( $tempFile );
            unlink ( $tempFile );
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While choosing between shared hosting and Cloud hosting I have always been inclined to
I have been struggling with this problem on hostgator shared hosting server for the
I have been attempting to set up magento on a shared hosting server that
I have an MVC2 app on shared hosting with a company... we'll call them
I have a cheap shared hosting plan with Reliablesite.net ($5/month). I've been making a
I have a shared hosting where I have my website and MySQL database. I've
I have shared hosting on CentOS with local MySQL database. I'm able to run
I set up a fossil repository on a shared hosting account I have. I
I have an application that runs on a shared hosting website - it is
I have a SQL Server 2005 database hosted on a shared hosting environment. Unfortunately

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.