在上传之前发布输入文件并重命名

i have this scenario in a codeigniter form_open_multipart:

enter image description here

now i want to upload the file with the name of the "Nome File" Field

this is my code:

public function aggiungiDocumento(){
        $nomeFile = $this->input->post('nomeFile');
        echo $nomeFile;
        $document = $_FILES['document']['name'];
        echo $document;
        if($document=''){

        }
        else {
            echo getcwd() . "
";
            $config['upload_path']='./aziende';
            echo $config['upload_path'];
            $config['allowed_types']='jpg|gif|png';
            $this->load->library('upload', $config);
            if(!$this->upload->do_upload('document')){
                echo "nope";
            }
            else{
                echo "yup";
                $config['file_name'] = $nomeFile;
                echo $config['file_name'];
                $document=$this->upload->data('file_name');
            }

        }

the upload work with the name of the attached not with nomeFile of the field that i posted

sorry for the english :) anyone can help me ? thanks a lot

This code placement is not right.

$config['file_name'] = $nomeFile;

Try this

public function aggiungiDocumento(){
    $nomeFile = $this->input->post('nomeFile');
    echo $nomeFile;
    $document = $_FILES['document']['name'];
    echo $document;
    if($document=''){

    }
    else {
        echo getcwd() . "
";
        $config['upload_path']='./aziende';
        echo $config['upload_path'];
        $config['allowed_types']='jpg|gif|png';
        //new file name process
        $tmp = explode('.', $document);
        $ext = end($tmp);
        $config['file_name'] = $nomeFile.$ext;
        $this->load->library('upload', $config);
        if(!$this->upload->do_upload('document')){
            echo "nope";
        }
        else{
            echo "yup";
            $config['file_name'] = $nomeFile;
            echo $config['file_name'];
            $document=$this->upload->data('file_name');
        }

    }