CI_Upload::set_filename PHP Метод

set_filename() публичный Метод

This function takes a filename/path as input and looks for the existence of a file with the same name. If found, it will append a number to the end of the filename to avoid overwriting a pre-existing file.
public set_filename ( string $path, string $filename ) : string
$path string
$filename string
Результат string
    public function set_filename($path, $filename)
    {
        if ($this->encrypt_name === TRUE) {
            $filename = md5(uniqid(mt_rand())) . $this->file_ext;
        }
        if ($this->overwrite === TRUE or !file_exists($path . $filename)) {
            return $filename;
        }
        $filename = str_replace($this->file_ext, '', $filename);
        $new_filename = '';
        for ($i = 1; $i < $this->max_filename_increment; $i++) {
            if (!file_exists($path . $filename . $i . $this->file_ext)) {
                $new_filename = $filename . $i . $this->file_ext;
                break;
            }
        }
        if ($new_filename === '') {
            $this->set_error('upload_bad_filename', 'debug');
            return FALSE;
        } else {
            return $new_filename;
        }
    }