Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
taskonsite-архив-перенесен
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitry Korolev
taskonsite-архив-перенесен
Commits
79d7fcd7
Commit
79d7fcd7
authored
Apr 14, 2016
by
Shakarim Sapa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Добавлено сохранение переданного файла в файловой системе, и указание пути к нему в базе
parent
32be3feb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
0 deletions
+35
-0
common/modules/analyticsSchool/models/AnalyticsSchoolLessonFile.php
...ules/analyticsSchool/models/AnalyticsSchoolLessonFile.php
+35
-0
No files found.
common/modules/analyticsSchool/models/AnalyticsSchoolLessonFile.php
View file @
79d7fcd7
...
...
@@ -3,6 +3,7 @@
namespace
common\modules\analyticsSchool\models
;
use
Yii
;
use
yii\web\UploadedFile
;
/**
* This is the model class for table "analytics_school_lesson_file".
...
...
@@ -11,12 +12,15 @@ use Yii;
* @property integer $lesson_id
* @property string $title
* @property string $file
* @property UploadedFile $document
*
* @property AnalyticsSchoolLesson $lesson
*/
class
AnalyticsSchoolLessonFile
extends
\yii\db\ActiveRecord
{
public
$document
;
protected
$save_folder
=
[
'uploads'
,
'lessons'
];
/**
* @inheritdoc
*/
...
...
@@ -25,6 +29,37 @@ class AnalyticsSchoolLessonFile extends \yii\db\ActiveRecord
return
'analytics_school_lesson_file'
;
}
public
function
beforeSave
(
$insert
){
if
(
!
parent
::
beforeSave
(
$insert
))
return
false
;
// Сгенерировали имя папки
$dirname
=
Yii
::
$app
->
security
->
generateRandomString
(
5
);
// Определили mime тип файла и занесли его в массив
$fileFormat
=
explode
(
'/'
,
$this
->
document
->
type
);
// Сгенерировали новое имя для файла
$fileName
=
Yii
::
$app
->
security
->
generateRandomString
(
5
)
.
'.'
.
$fileFormat
[
1
];
// Определили папку в которую будет загружен файл
$saveDir
=
$this
->
getPath
()
.
DIRECTORY_SEPARATOR
.
$dirname
;
// Если папка не найдена
if
(
!
is_dir
(
$saveDir
))
// Создаем ее (рекурсивно)
mkdir
(
$saveDir
,
0777
,
true
);
// Если до этого момента действие не было остановлено - сохраняем файл в файловой системе
if
(
$this
->
document
->
saveAs
(
$saveDir
.
DIRECTORY_SEPARATOR
.
$fileName
))
{
// Переопределяем значение в поле
$this
->
file
=
$this
->
getPath
(
false
,
'/'
)
.
'/'
.
$dirname
.
'/'
.
$fileName
;
}
return
true
;
}
public
function
getPath
(
$absolute
=
true
,
$delimiter
=
DIRECTORY_SEPARATOR
)
{
$path
=
$delimiter
.
(
implode
(
$delimiter
,
$this
->
save_folder
));
return
(
$absolute
===
true
)
?
Yii
::
getAlias
(
'@frontend'
)
.
$delimiter
.
'web'
.
$path
:
$path
;
}
/**
* @inheritdoc
*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment