Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

235
Vistas
Codeigniter File Validation without "required" parameter

I want to create file validation which not mandatory but when it is inserted, it has to be zip file and max_size 2MB. I use Codeigniter 4 & Js, With the code below, when the input[file] is empty, I still get validation error.

$("#btnReply").click(function(e) {
    var frmReply = new FormData();
    frmReply.append('attachment_reply', $('#attachment_reply')[0].files[0]);

    e.preventDefault();
    $.ajax({
        type: 'POST',
        url: 'http://localhost/syst20/ticketreply/store',
        enctype: 'multipart/form-data',
        dataType: 'json',
        data: frmReply,
});

My Controller Rule

        if (!$this->validate([
            'attachment_reply' => [
                'label' => 'Attachment',
                'rules' => 'ext_in[attachment_reply,zip,rar,7z]|max_size[attachment_reply,2000]',
            ]])) {

            $error_description = $this->validator->getErrors();

            $callback = array(
                'status' => 'failed',
                'message' => $error_description,
                'ticket_id' => $ticket_id,
                'token' => csrf_hash(),
            );
        }
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda