minaremonshaker's avatar

Why do the image and mimetypes still give me errors in the error bag when I'm uploading the right file extension and Type?

Hello, I'm building an admin dashboard form to register new users, which includes a profile image upload feature. However, I'm encountering a problem where uploading an image file (Aron.png) continues to fail validation

Illuminate\Support\ViewErrorBag {#593 ▼
  #bags: array:1 [▼
    "default" => 
Illuminate\Support
\
MessageBag
 {#587 ▼
      #messages: array:1 [▼
        "profile_image" => array:3 [▼
          0 => "The profile image field must be an image."
          1 => "The profile image field must be a file of type: image/png, image/jpeg."
          2 => "The profile image field has invalid image dimensions."
        ]
      ]
      #format: ":message"
    }
  ]
}
   public function rules(): array
    {
        return [
           'profile_image' => 'required|image|mimetypes:image/png,image/jpeg|max:2048|dimensions:min_width=300,min_height=300'
        ];
    }
0 likes
8 replies
minaremonshaker's avatar

@JussiMannisto i forgot to add it , but now i have added it and i have The POST data is too large. , what i did i added .htaccess file and i addd this to it , but this dose not take any effect , this means that i have to change the php.ini file and i am not a big fan of that , i like to do it per project

php_value post_max_size 50M
php_value upload_max_filesize 50M
php_value memory_limit 256M
php_value max_execution_time 300

JussiMannisto's avatar

@minaremonshaker The .htaccess file is only used by Apache. Are you're serving the site with Apache, and not Nginx, php artisan serve, Herd, or something else?

JussiMannisto's avatar
Level 50

@minaremonshaker You can inject PHP values in the virtual host config of whatever web server you're using. So you can customize the config for specific sites if you want to avoid changing php.ini. Not sure how to do that with the PHP development server, though.

Is the error actually coming from your web server, or is it a validation error from Laravel? Did you try removing the max:2048 rule to see if that's causing it? You didn't include file as a validation rule, which might make Laravel use the max rule incorrectly. I don't remember if using image is enough.

Please or to participate in this conversation.