Welcome Guest, Not a member yet? Register   Sign In
problems validation image
#3

(This post was last modified: 05-26-2021, 10:48 PM by bengtdg.)

(05-26-2021, 09:13 PM)InsiteFX Wrote: Read this.

CodeIgniter 4 User Guide - Working with Uploaded Files

Thank you. I have read there. 

It failes here when validation of image fails...
PHP Code:
if(isset($postData['submit'])){
        
   ## Validation
        
   $input $this->validate([
            
  'kategori' => 'required|min_length[3]|is_unique[kategori.kategori]',
            
  'image' => 'uploaded[image]|max_size[image, 4]',
            
  ]);
            echo 
"<pre>var_dump: \$_POST: "var_dump($_POST); echo "</pre>";
            
            echo 
"<pre>var_dump: \$_FILES: "var_dump($_FILES); echo "</pre>";
        
   if (!$input) {  ////IT FAILS HERE
            
   echo "failed";
            
  //return redirect()->to('/admin/cat/create')->withInput()->with('validation',$this->validator); 
        
   } else { 

som var dump from the var dumps above 
Code:
$request = service('request');
        $postData = $request->getPost();

        echo "<pre>"; print_r($postData); echo "</pre>";


Array
(
    [kategori] => gfdfgdsfg
    [submit] =>
)


var_dump: $_POST:
C:\www\kalori\app\Controllers\CatController.php:40:
array (size=2)
  'kategori' => string 'gfdfgdsfg' (length=9)
  'submit' => string '' (length=0)

var_dump: $_FILES:
C:\www\kalori\app\Controllers\CatController.php:42:
array (size=1)
  'image' =>
    array (size=5)
      'name' => string 'Bengt.jpg' (length=9)
      'type' => string 'image/jpeg' (length=10)
      'tmp_name' => string 'C:\wamp64\tmp\php4934.tmp' (length=25)
      'error' => int 0
      'size' => int 1049248
failed

It just pussles me. If validation of kategori fails, it returns the error message .
But nothing happens when validation of image fails. The validation error never comes back to the form.

If i set max_file to 4096 then the file is successfully uploaded.
Reply


Messages In This Thread
problems validation image - by bengtdg - 05-26-2021, 04:00 PM
RE: problems validation image - by InsiteFX - 05-26-2021, 09:13 PM
RE: problems validation image - by bengtdg - 05-26-2021, 10:46 PM
RE: problems validation image - by InsiteFX - 05-27-2021, 05:38 AM
RE: problems validation image - by paliz - 05-27-2021, 10:09 AM



Theme © iAndrew 2016 - Forum software by © MyBB