user4383363
user4383363

Reputation:

Input file is accused to be empty by CodeIgniter form_validation

I have an input for file uploading that has required rule, but even when selecting one, the framework accuses it to be empty and throws the error. Below is the rules:

$config = array(
    'registro_fisica' => array(
        array(
            'field' => 'imagem',
            'label' => 'IMAGEM',
            'rules' => 'required'
        ),
        ...

Below, the form:

<form action="/auto/usuario/add" method="POST" name="fisica_1" id="formulario_fisica_1" class="form_registro" enctype="multipart/form-data">
    <input type="hidden" name="tipo_usuario" value="F"/>
    <div class="p100">
        <div class="left">
            <span class="titulo">Dados Pessoais e Foto</span>
            <input type="file" name="imagem" id="imagem"/>
            ...

That's it. Even I have chose a file, an error is thrown.

Upvotes: 0

Views: 51

Answers (1)

Gwendal
Gwendal

Reputation: 1273

Required rule doesn't seem to work with files, use callback instead. Take a look at http://keighl.com/post/codeigniter-file-upload-validation/

Upvotes: 0

Related Questions