Skip to content

Commit 7265abc

Browse files
committed
Add getFileRealPath
1 parent cd0347b commit 7265abc

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/behaviors/FileBehavior.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,18 @@ public function isProtected($attribute)
125125
return ArrayHelper::getValue($this->attributes[$attribute], 'protected', false);
126126
}
127127

128+
/**
129+
* Get real path to file
130+
*
131+
* @param string $attribute
132+
* @return string
133+
*/
134+
public function getFileRealPath($attribute)
135+
{
136+
$realPath = $this->getUploadDir($attribute);
137+
return $realPath . $this->owner->$attribute;
138+
}
139+
128140
/**
129141
* Get upload dir
130142
*

tests/FileUploadTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,4 +353,15 @@ public function testFailCreateFromPath()
353353
{
354354
$file = Yii::$app->fileManager->create('/test/fail.jpg', 100, 200, true, false);
355355
}
356+
357+
public function testRealPath()
358+
{
359+
extract($this->uploadFile([
360+
'modelName' => News::className(),
361+
'attribute' => 'image_path',
362+
'inputName' => 'file-300'
363+
]));
364+
365+
$this->assertFileExists($model->getFileRealPath('image_path'));
366+
}
356367
}

0 commit comments

Comments
 (0)