Error while uploading codeigniter files

Asked

Viewed 229 times

1

I’m having a problem that I can’t resolve regarding uploading files in php with codeigniter

upload but get back the message that I have not selected any file for upload.

View:

<form id='formsolicitacao' method='POST' action="ubs/index" enctype="multipart/form-data">
    <input type="file" name="userfile" />
    <input type="submit" name="submit" class="btn btn-primary" value="Enviar" />
</form>

Controller:

public function index(){

        if($this->input->post('submit')){
            $configuracao = array(
                'upload_path'          => './uploads/',
                'allowed_types'        => 'gif|jpg|png|bmp|pdf|jpeg',
                'max_size'             => 0,
                'max_width'            => 0,
                'max_height'           => 0
            );

            $this->load->library('upload');

            $this->upload->initialize($configuracao);


            if (!$this->upload->do_upload('userfile'))
            {
                $arquivo = '';


                var_dump($this->input->post('userfile'));
                var_dump(array('error' => $this->upload->display_errors()) );


                echo "nao";
            }
            else
            {
                $arquivo =  base_url() . 'uploads/' . $this->upload->data('file_name');

                echo "sim";
            }


            //$dados['resposta'] = $this->modelsolicitacoes->inserir($arquivo);

            echo "submit";
        }


    }

Note: I took excerpts from the code that I think is not important to the question

the return I get is this:

C:\wamp64\www\boldrini\application\controllers\Ubs.php:42:string 'roda6.jpeg' (length=10)
C:\wamp64\www\boldrini\application\controllers\Ubs.php:43:
array (size=1)
  'error' => string '<p>Você não selecionou o arquivo para fazer upload.</p>' (length=57)
naosubmit

That is: var_dump recognizes that there is something in the post variable, but upload does not recognize.

I tried to put the upload function in a helper, in the model, already tried to change the array settings $configuracao, Anyway, I don’t know what I can do to make it work.

If anyone can give me a light, I’d really appreciate it

  • Tip: Do not remove parts of the code you do not think is relevant. I tested your code in a MS Windows environment and did not have a problem. The upload occurs normally. Check the permissions of upload_path.

  • 1

    Thanks for the @Shutupmagda tip. I managed to solve the problem

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.