Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

230
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!