Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Check content type in PHP

    In PHP, when a script uploads a file from a user, is it possible to check the mime type of the file?

    Something like this...

    $uploaded_type = METHOD_FOR_GETTING_TYPE_OF_FILE($uploaded);

    if ($uploaded_type =="text/php"){
    $rejectfile = 1;
    }

  • #2
    Regular Coder
    Join Date
    Jan 2012
    Posts
    271
    Thanks
    2
    Thanked 65 Times in 65 Posts
    you mean when a user uploads a file to your site right?

    if so, yes.. it will be in the $_FILES variable... print_r($_FILES) and you will see it and will be able write code to reject filetypes that you don't want

    there's some good info here: http://php.net/manual/en/reserved.variables.files.php

  • #3
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Awesome!

    Any idea on how "effective" this is? Any feedback on if it's pretty effective?

    If it's just grabbing the extension and not actually checking the file it may not be much different than what I'm doing currenlty.

  • #4
    Regular Coder
    Join Date
    Jan 2012
    Posts
    271
    Thanks
    2
    Thanked 65 Times in 65 Posts
    i 'believe' it does check the mime type... but not 100% sure..

    you can easily test it by renaming a file extension and see what the process says it is..


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •