Пример #1
0
 /**
  * Generate links to files to use them as messages.
  * @param string $type Message type, ok or error.
  * @return array
  */
 private function linksToFiles($type = 'ok')
 {
     $array = $type == 'ok' ? $this->_oks : $this->_errors;
     $files = File::find()->where(['guid' => array_keys($array)])->all();
     foreach ($files as $file) {
         $array[$file->guid] = Url::to(['file/' . $file->guid]);
     }
     return $array;
 }
Пример #2
0
 /**
  * Copy file name to GUIDs.
  * @param string[] $guids
  * @return BatchResult
  */
 public static function guidFromName($guids)
 {
     $result = new BatchResult();
     $files = File::find()->where(['guid' => $guids])->all();
     foreach ($files as $file) {
         $guid = $file->guid;
         $file->guid = $file->name;
         if ($file->save()) {
             $file->rename($file->guid);
             $result->ok($file->guid);
         } else {
             $result->error($guid);
         }
     }
     return $result;
 }
Пример #3
0
 public function actionUpload()
 {
     $flow = new Flow();
     $flow->tmpDir = $this->module->tmppath;
     $flow->targetDir = $this->module->filepath;
     if ($flow->isUploading) {
         $guid = $flow->getParam('identifier');
         if ($flow->isNew) {
             $filename = $flow->getParam('filename');
             $file = new File();
             $file->guid = $guid;
             $file->name = pathinfo($filename, PATHINFO_FILENAME);
             $file->extension = pathinfo($filename, PATHINFO_EXTENSION);
             $file->save();
         } else {
             $file = File::findOne(['guid' => $guid]);
         }
         $flow->uploadChunk();
         if ($flow->isComplete) {
             $targetDir = $this->module->filepath . '/' . $file->guid[0] . '/' . $file->guid[1];
             $flow->targetDir = $targetDir;
             $flow->save($file->guid);
             if (file_exists($targetDir . '/' . $flow->savedFilename)) {
                 $file->status = File::S_OK;
                 $file->path = $file->guid[0] . '/' . $file->guid[1] . '/' . $flow->savedFilename;
                 $file->size = (string) filesize($targetDir . '/' . $flow->savedFilename);
                 $file->save();
             } else {
                 $file->status = File::S_ERROR;
                 $file->message = Yii::t('vps-uploader', 'Error saving file to path {path}.', ['path' => $file->guid[0] . '/' . $file->guid[1] . '/' . $flow->savedFilename]);
                 $file->save();
             }
         } elseif ($file->status != File::S_UPLOADING) {
             $file->status = File::S_UPLOADING;
             $file->save();
         }
         // @TODO: output errors
     } else {
         $flow->testChunk();
     }
     Yii::$app->end();
 }
Пример #4
0
 public function actionIndex()
 {
     $this->title = Yii::t('vps-uploader', 'VPS uploader');
     $this->data('last', File::find()->orderBy(['dt' => SORT_DESC])->limit(20)->all());
 }
Пример #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getFile()
 {
     return $this->hasOne(File::className(), ['guid' => 'fileGuid']);
 }