CodeIgniter Forums
[VALIDATION] - Upload excel fail - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: [VALIDATION] - Upload excel fail (/showthread.php?tid=91892)



[VALIDATION] - Upload excel fail - ddevsr - 10-31-2024

I have validation file upload excel

PHP Code:
if ($this->request->getFile('fileBuktiSelisihTxt')) {
            $folderLocationKonfirmasi $this->getFolderKonfirmasiData($idKreditur);

            if ($this->validate([
                'fileBuktiSelisihTxt' => [
                    'label' => 'Data Selisih Polis Batal',
                    'rules' => [
                        'uploaded[fileBuktiSelisihTxt]',
                        'ext_in[fileBuktiSelisihTxt,xlsx,xls]',
                        'mime_in[fileBuktiSelisihTxt,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel,application/msexcel,application/x-msexcel,application/x-ms-excel,application/x-excel,application/x-dos_ms_excel,application/xls,application/x-xls,application/excel,application/download,application/vnd.ms-office,application/msword]',
                        'max_size[fileBuktiSelisihTxt,1048]',
                    ],
                ],
            ])) {
                $errors $this->validation->getErrors();

                $arrReturnInvalid = [
                    'r_status' => false,
                    'r_data'  => [
                        'status'  => 'warning',
                        'message' => $errors,
                    ],
                    'r_code'    => 400,
                    'r_message' => 'Bad Request',
                ];

                return json_encode($arrReturnInvalidJSON_PRETTY_PRINT);
            }

            $params_file $this->request->getFile('fileBuktiSelisihTxt');

            if ($params_file->isValid() && ! $params_file->hasMoved()) {
                $extFile  $params_file->getExtension();
                $timeNow  Time::now();
                $makeFile $params_file->getBasename('.' $extFile) . '_' $timeNow->getTimestamp() . '_CHECK.' $extFile;

                \log_message('info''MASUK SNI APPROVAL');

                if ($params_file->move($folderLocationKonfirmasi$makeFiletrue)) {
                    \log_message('info''MASUK SANA APPROVAL');
                    $postData['fileBuktiSelisih'] = $makeFile;
                }
            }
        


And here var_dump($_FILES);

Code:
array(2) {
  ["fileBuktiPolisTxt"]=>
  array(6) {
    ["name"]=>
    string(37) "ajukan-xxxx-2024-10-15-11-4-20.xlsx"
    ["full_path"]=>
    string(37) "ajukan-xxxx-2024-10-15-11-4-20.xlsx"
    ["type"]=>
    string(65) "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
    ["tmp_name"]=>
    string(46) "C:\Users\ABC-PC\AppData\Local\Temp\php174A.tmp"
    ["error"]=>
    int(0)
    ["size"]=>
    int(17920)
  }
  ["fileBuktiCancelPolisTxt"]=>
  array(6) {
    ["name"]=>
    string(18) "xxxxx.xlsx"
    ["full_path"]=>
    string(18) "xxxxx.xlsx"
    ["type"]=>
    string(65) "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
    ["tmp_name"]=>
    string(46) "C:\Users\ABC-PC\AppData\Local\Temp\php174B.tmp"
    ["error"]=>
    int(0)
    ["size"]=>
    int(9047)
  }
}

How solve this?


RE: [VALIDATION] - Upload excel fail - InsiteFX - 10-31-2024

What is a correct MIME type for .docx, .pptx, etc.?


RE: [VALIDATION] - Upload excel fail - ddevsr - 11-01-2024

Already correct config/Mimes


RE: [VALIDATION] - Upload excel fail - ddevsr - 11-03-2024

I found problem is getMimeType(), the function give mime type application/encrypted. I think because it was passworded and reopened.

Already test in CI4 base code and my project
PHP Code:
vendor/bin/phpunit tests/system/Validation/FileRulesTest.php
PHPUnit 11.4.3 by Sebastian Bergmann 
and contributors.

Runtime:      PHP 8.3.13 with Xdebug 3.3.2
Configuration
D:\Project\laragon\www\ci4\phpunit.xml.dist

FF
┌──────────────────────────────────────────────────────────────────────────────┐
│ $file
->getMimeType()                                                        │
└──────────────────────────────────────────────────────────────────────────────┘
string 
(19"application/encrypted"
┌──────────────────────────────────────────────────────────────────────────────┐
│ $file
->getClientExtension()                                                  │
└──────────────────────────────────────────────────────────────────────────────┘
string 
(3"xls"
┌──────────────────────────────────────────────────────────────────────────────┐
│ $file
->guessExtension()                                                      │
└──────────────────────────────────────────────────────────────────────────────┘
string 
(0""
┌──────────────────────────────────────────────────────────────────────────────┐
│ $params                                                                      │
└──────────────────────────────────────────────────────────────────────────────┘
array (2) [
    0 => string (3"xls"
    1 => string (4"xlsx"
]
════════════════════════════════════════════════════════════════════════════════
Called from 
<ROOT>/system/Validation/FileRules.php:210 [dd()]