protected function setNewFileName()
    {
        $this->new_file_name = trim($this->new_file_name);

        if ($this->new_file_name == null) {
            // if new file name was not set, set it from uploaded file name.
            if (is_array($this->files[$this->input_file_name]) && array_key_exists('name', $this->files[$this->input_file_name])) {
                $file_name_explode = explode('.', $this->files[$this->input_file_name]['name']);
                unset($file_name_explode[count($file_name_explode)-1]);
                $this->new_file_name = implode('.', $file_name_explode);
                unset($file_name_explode);
            } else {
                $this->setNewFileNameToRandom();
            }
        }

        // do not allow name that contain one of these characters.
        $reserved_characters = array('\\', '/', '?', '%', '*', ':', '|', '"', '<', '>', '!', '@');
        $this->new_file_name = str_replace($reserved_characters, '', $this->new_file_name);
        unset($reserved_characters);

        if (preg_match('#[^\.]+#iu', $this->new_file_name) == 0) {
            // found the name is only dots. example ., .., ..., ....
            $this->setNewFileNameToRandom();
        }

        // reserved words or reserved names. do not allow if new name is set to one of these words or names.
        // make it case in-sensitive.
        $reserved_words = array(
            'CON', 'PRN', 'AUX', 'CLOCK$', 'NUL', 
            'COM1', 'COM2', 'COM3', 'COM4', 'COM5', 'COM6', 'COM7', 'COM8', 'COM9', 
            'LPT1', 'LPT2', 'LPT3', 'LPT4', 'LPT5', 'LPT6', 'LPT7', 'LPT8', 'LPT9',
            'LST', 'KEYBD$', 'SCREEN$', '$IDLE$', 'CONFIG$',
            '$Mft', '$MftMirr', '$LogFile', '$Volume', '$AttrDef', '$Bitmap', '$Boot', '$BadClus', '$Secure',
            '$Upcase', '$Extend', '$Quota', '$ObjId', '$Reparse',
        );
        foreach ($reserved_words as $reserved_word) {
            if (strtolower($reserved_word) == strtolower($this->new_file_name)) {
                $this->setNewFileNameToRandom();
            }
        }
        unset($reserved_word, $reserved_words);

        // in the end if it is still left new name as null... set random name to it.
        if ($this->new_file_name == null) {
            $this->setNewFileNameToRandom();
        }
    }