Uploading files and validation rules with mobile devices

This is my Upload.php


namespace app\models;

use yii\base\Model;

use yii\web\UploadedFile;


 * UploadForm is the model behind the upload form.


class Upload extends Model



     * @var UploadedFile|Null file attribute


    public $file;


     * @return array the validation rules.


    public function rules()


        return [

            [['file'], 'file'],

            [['file'], 'file', 'skipOnEmpty' => false],

            [['file'], 'file', 'extensions' => 'jpg'],

            [['file'], 'file', 'mimeTypes' => 'image/jpeg'],

            [['file'], 'file', 'minSize' => '51200'],

            [['file'], 'file', 'maxSize' => '8388608']




This works fine with an image uploaded from a common pc. But with an android smartphone, it fail in mimeTypes and minSize too. The exactly same image!

This happens not with all android smartphones, I think, but with a Samsung S5570I certainly happens.

How do you would start to investigate, please? (My fantasy ended)

You should add ‘jpeg’ to you extensions.

MinSize and maxSize are integers and you have them as strings.

You should group your rules together, add jpeg to ext, and make min/maxSize an integer. Try this out and report back.

['file', 'file', 'skipOnEmpty' => false, 'extensions' => ['jpg','jpeg'], 'mimeTypes' => 'image/jpeg', 'minSize' => 51200, 'maxSize' => 8388608], 

You’re right, but nothing has changed, 'cause the problem is another. And this is a big problem regarding any image you try to upload with any smartphone and yii validation rule philosophy.

If you try to load an image file of your pc, you point to the real file, so the validation rule works fine. But if you try to load an image file from your smartphone, you don’t point to the real file to upload to, but to the thumbnail related. So the validation, obviously, fails.

And this is a really big problem, but for this and other cases the apps for smartphones exists. :slight_smile: