Commit dcf8831a authored by Shakarim Sapa's avatar Shakarim Sapa

- Добавили предварительное удаление старого файла

parent fd62688f
...@@ -68,6 +68,9 @@ class AnalyticsSchoolCourse extends \common\components\ActiveRecordModel ...@@ -68,6 +68,9 @@ class AnalyticsSchoolCourse extends \common\components\ActiveRecordModel
// Если валидация неуспешная, возвращаем false // Если валидация неуспешная, возвращаем false
return false; return false;
// Удалили старый файл перед загрузкой нового
$this->deleteFile();
// Сгенерировали путь к папке // Сгенерировали путь к папке
$dirname = Yii::$app->security->generateRandomString(5); $dirname = Yii::$app->security->generateRandomString(5);
// Определили mime тип файла и занесли его в массив // Определили mime тип файла и занесли его в массив
...@@ -97,9 +100,17 @@ class AnalyticsSchoolCourse extends \common\components\ActiveRecordModel ...@@ -97,9 +100,17 @@ class AnalyticsSchoolCourse extends \common\components\ActiveRecordModel
if (!parent::beforeDelete()) if (!parent::beforeDelete())
return false; return false;
$this->deleteFile();
return true;
}
/**
* @return bool
*/
public function deleteFile(){
$filepath = Yii::getAlias('@frontend').$this->image; $filepath = Yii::getAlias('@frontend').$this->image;
if (file_exists($filepath)) { if (file_exists($filepath)) {
unlink($filepath); return unlink($filepath);
} }
return true; return true;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment