Welcome Guest, Not a member yet? Register   Sign In
Uploads multiple files with validation

I am a problem when i upload multiples files and i want validate all files.

my view form:
PHP Code:
<form id="new-fotos-form">
            <div class="modal-body">
                <div class="form-group">
                    <input type="text" class="form-control" id="id_producto" name="id_producto" hidden value="<?=$producto->id?>">
                    <?/*= form_hidden('id', $producto->id); */?>
                <h4>Selecciona ficheros (puedes seleccionar varios a la vez)</h4>
                <div class="input-group">
                    <div class="custom-file">
                        <input type="file" class="custom-file-input" name="images[]" multiple id="nuevas_fotos">
                        <label class="custom-file-label" for="nuevas_fotos"></label>
            <div class="modal-footer justify-content-between">
                <button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
                <button type="button" class="btn btn-primary" onclick="insertFotosNew('<?=base_url('subir_fotos')?>')">Subir foto</button>

my validation rules:
PHP Code:
public $foto = [
        'images[]' => 'is_image[images[]]|mime_in[images[],application/anything]|uploaded[images[]]|max_size[images[],350]|max_dims[images[],3200,2128]'
    public $foto_errors = [
        'images[]' => [
            'is_image' => 'Alguna imagen seleccionada no es válida.',
            'mime_in'  => 'Error de tipo mime de fichero',
            'uploaded' => 'Hay algún problema con uno de los ficheros (puede ser el nombre o que no sea un fichero válido),',
            'max_size' => 'El tamaño de uno de los ficheros es superior a 4Mb.',
            'max_dims' => 'Las dimensiones de alguno de los ficheros es superior a 3200 X 2128'

my controller for upload with the validation:
PHP Code:
public function run(){
        $todo       $this->request->getPost();
        $files      $this->request->getFiles();

        $data = array();
        $data['codeLib'] = $this->maskIdLib;
        $data['MYEncryptLib'] = $this->MYEncryptLib;
        $data['pathFotos'] = $this->configuracionRepository->getConfiguracionParametro('urlFotos');

        $validateFotos $this->MYvalidation->run($todo,'foto');

        if(count($files) > and $validateFotos) {
            $this->respuesta $this->propiedadNewFotoUpload($todo['id_producto'], $files);
            $data['fotos'] =  $this->productosFotosRepository->getProductoFotos($todo['id_producto']);
        else  {
            $this->respuesta->mensaje 'No hay ficheros para subir o no son válidos';
            $this->respuesta->estado EXIT_ERROR;
            $this->respuesta->datos $this->MYvalidation->listErrors();
            $data['fotos'] = $this->productosFotosRepository->getProductoFotos($todo['id_producto']);
        $data['validation'] = $this->MYvalidation->listErrors();

        echo view('Administracion/Propiedades/propiedades_form_fotos'$data);

If i try upload the files with no check validation this upload correctly.
But if i check the validation ($this->MYvalidation->run($todo,'foto');) then always occurs the same error is_image who is the first validation rule. If the first validation rule is 'uploaded' or another, always occurs the first rule.

In propiedadNewFotoUpload (the method for upload the files) check is_valid() )

can anyone help me??


probaste sacandole los corchetes [] a "images"?

I got the same problem, did u get the solution ?

(06-04-2020, 03:01 AM)hi, i am not sure but just try using this one : Wrote:

(This post was last modified: 03-12-2021, 05:51 PM by InsiteFX.)

CodeIgniter 4 Single and Multiple Files Upload Examples
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

Theme © iAndrew 2016 - Forum software by © MyBB