yii-dream-team / yii2-upload-behavior

Yii2 file/image upload behavior for ActiveRecord
http://yiidreamteam.com/yii2/upload-behavior
MIT License
77 stars 45 forks source link

Multi attributes #3

Closed timmy78 closed 9 years ago

timmy78 commented 9 years ago

I made like in #1 @russianlagman But when I submit my form, there is an error : Image file not found: C:/.../web/images/application/1/ios.jpg

The image and the thumbs of the first attribute are saved, but not for the other attributes.

My configuration :

public function behaviors()
{
    return [
        'image-upload-android' => [
            'class' => '\yiidreamteam\upload\ImageUploadBehavior',
            'attribute' => 'android_logo',
            'thumbs' => [
                'index' => ['width' => 50, 'height' => 40],
                'view' => ['width' => 400, 'height' => 300],
            ],
            'filePath' => '[[web_root]]/images/[[model]]/[[id]]/[[basename]]',
            'fileUrl' => '[[base_url]]/images/[[model]]/[[id]]/[[basename]]',
            'thumbPath' => '[[web_root]]/images/[[model]]/[[id]]/[[profile]]_android_[[id]].[[extension]]',
            'thumbUrl' => '[[base_url]]/images/[[model]]/[[id]]/[[profile]]_android_[[id]].[[extension]]',
        ],
        'image-upload-ios' => [
            'class' => '\yiidreamteam\upload\ImageUploadBehavior',
            'attribute' => 'ios_logo',
            'thumbs' => [
                'index' => ['width' => 50, 'height' => 40],
                'view' => ['width' => 400, 'height' => 300],
            ],
            'filePath' => '[[web_root]]/images/[[model]]/[[id]]/[[basename]]',
            'fileUrl' => '[[base_url]]/images/[[model]]/[[id]]/[[basename]]',
            'thumbPath' => '[[web_root]]/images/[[model]]/[[id]]/[[profile]]_ios_[[id]].[[extension]]',
            'thumbUrl' => '[[base_url]]/images/[[model]]/[[id]]/[[profile]]_ios_[[id]].[[extension]]',
        ],
        'image-upload-windows' => [
            'class' => '\yiidreamteam\upload\ImageUploadBehavior',
            'attribute' => 'windows_logo',
            'thumbs' => [
                'index' => ['width' => 50, 'height' => 40],
                'view' => ['width' => 400, 'height' => 300],
            ],
            'filePath' => '[[web_root]]/images/[[model]]/[[id]]/[[basename]]',
            'fileUrl' => '[[base_url]]/images/[[model]]/[[id]]/[[basename]]',
            'thumbPath' => '[[web_root]]/images/[[model]]/[[id]]/[[profile]]_windows_[[id]].[[extension]]',
            'thumbUrl' => '[[base_url]]/images/[[model]]/[[id]]/[[profile]]_windows_[[id]].[[extension]]',
        ],
    ];
}

Thanks ;)

metalagman commented 9 years ago

you've got the same

            'filePath' => '[[web_root]]/images/[[model]]/[[id]]/[[basename]]',
            'fileUrl' => '[[base_url]]/images/[[model]]/[[id]]/[[basename]]',

but I think they should be different

timmy78 commented 9 years ago

The same what ? Basename should be different in each attribute because it will be replaced by his attribute image basename.

metalagman commented 9 years ago

I you upload the file with the same name into different attributes, It the former will be rewritten by the later and you'll get 1 file stored instead of 3.

timmy78 commented 9 years ago

The 3 files have not the same name

timmy78 commented 9 years ago

Works nice since the update, thanks !