I wrote the following php function to upload files but I'm having a hard time with the array of allowed file types. If I assign just one file type i.e. image/png, it works fine. If I assign more than one, its not working. I use the in\_array() function to determine the allowed file types but I can't figure out how to use it properly.

Thank you!

```
function mcSingleFileUpload($mcUpFileName, $mcAllowedFileTypes, $mcFileSizeMax){
    if(!empty($mcUpFileName)){

        $mcIsValidUpload = true;

        // upload directory
        $mcUploadDir = UPLOAD_DIRECTORY;

        // current file properties
        $mcFileName = $_FILES[$mcUpFileName]['name'];
        $mcFileType = $_FILES[$mcUpFileName]['type'];
        $mcFileSize = $_FILES[$mcUpFileName]['size'];
        $mcTempFileName = $_FILES[$mcUpFileName]['tmp_name'];
        $mcFileError = $_FILES[$mcUpFileName]['error'];

        // file size limit
        $mcFileSizeLimit = $mcFileSizeMax;

        // convert bytes to kilobytes
        $mcBytesInKb = 1024;
        $mcFileSizeKb = round($mcFileSize / $mcBytesInKb, 2);

        // create array for allowed file types
        $mcAllowedFTypes = array($mcAllowedFileTypes);

        // create unique file name
        $mcUniqueFileName = date('m-d-Y').'-'.time().'-'.$mcFileName;

        // if file error
        if($mcFileError > 0)
        {
            $mcIsValidUpload = false;
            mcResponseMessage(true, 'File error!');
        }

        // if no file error
        if($mcFileError == 0)
        {
            // check file type
            if( !in_array($mcFileType, $mcAllowedFTypes) ){
                $mcIsValidUpload = false;
                mcResponseMessage(true, 'Invalid file type!');
            }

            // check file size
            if( $mcFileSize > $mcFileSizeLimit ){
                $mcIsValidUpload = false;
                mcResponseMessage(true, 'File exceeds maximum limit of '.$mcFileSizeKb.'kB');
            }

            // move uploaded file to assigned directory
            if($mcIsValidUpload == true){
                if(move_uploaded_file($mcTempFileName, $mcUploadDir.$mcUniqueFileName)){
                    mcResponseMessage(false, 'File uploaded successfully!');
                }
                else{
                    mcResponseMessage(true, 'File could not be uploaded!');
                }
            }
        }
    }
}
//mcRequiredFile('mcFileUpSingle','please select a file to upload!');
mcSingleFileUpload('mcFileUpSingle', 'image/png,image/jpg', 2097152);

```