how to determine the correct extension file is uploaded???

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vishal

    how to determine the correct extension file is uploaded???

    i am allowing user to add file upload to server and the suer can put
    only those files which display some image i.e. jpg or gif or other
    photo file. so how can i check that the user has selected correct type
    of file to upload

    thxs for help in advance

  • rovisoft

    #2
    re:how to determine the correct extension file is uploaded???

    This is a small function that will return the file extension, all you
    have to do is to compare it with what you allow:

    function get_ext($filena me)
    {
    $file=explode(" .",$filename );
    return $file;
    }

    Or you can check the file type, if it's image/gif, image/jpeg or
    image/png! You can do that with this function, where $f is the full
    path to the file
    if (!function_exis ts('mime_conten t_type')) {
    function mime_content_ty pe($f) {
    $f = escapeshellarg( $f);
    return trim( `file -bi $f` );
    }
    }


    Ovidiu:)


    DevPlug.com Forum

    Comment

    • Chung Leong

      #3
      Re: how to determine the correct extension file is uploaded???



      Comment

      Working...