2

I'm using flutter to upload files to a Php codeigniter 4 server. My problem is when I add validation for the uploaded file type. It always return file does not have a valid file extension.

Upload.php

$rules = [
 'file' => 'uploaded[file]|max_size[file, 4096]|ext_in[file,jpg,jpeg,png,doc,docx,pdf]'
];

Here is the debug of $_FILES that I recieved.

{"file":{"name":"file_test.jpg","type":"application\/octet-stream","tmp_name":"C:\\xampp\\tmp\\php623C.tmp","error":0,"size":169233}}
unice
  • 2,655
  • 5
  • 43
  • 78
  • Have you tried to add ".tmp" extension in your ext_in? Because your file is not actually a .jpg when importing it through $_FILES variable but a .tmp. – ViLar Nov 27 '20 at 07:28

1 Answers1

0

You missed the form field

enctype="multipart/form-data"
vimuth
  • 5,064
  • 33
  • 79
  • 116
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 10 '22 at 06:24