public function actionIndex()
 {
     $result = FileModule::getInstance()->upload();
     if (isset($result['errors'])) {
         return Json::encode(['error' => implode(', ', $result['errors'])]);
     }
     // Send responses data
     return Json::encode(array_map(function ($file) {
         /** @var \app\file\models\File $file */
         return $file->getExtendedAttributes();
     }, $result));
 }
 public function actionIndex($uid)
 {
     /** @var File $file */
     $file = File::findOne($uid);
     if (!$file) {
         throw new NotFoundHttpException();
     }
     if (FileModule::getInstance()->xHeader !== false) {
         \Yii::$app->response->xSendFile($file->path, $file->downloadName, ['xHeader' => FileModule::getInstance()->xHeader]);
     } else {
         header('Content-Description: File Transfer');
         header('Content-Type: application/octet-stream');
         header('Content-Disposition: attachment; filename="' . $file->getDownloadName() . '"');
         header('Expires: 0');
         header('Cache-Control: must-revalidate');
         header('Pragma: public');
         header('Content-Length: ' . filesize($file->path));
         readfile($file->path);
     }
 }
 protected static function cloneOriginal($fileUid, $suffix)
 {
     // Get original image
     /** @var self $originalMeta */
     $originalMeta = self::findOriginal($fileUid);
     if (!$originalMeta) {
         throw new FileException('Not found original image by uid `' . $fileUid . '`.');
     }
     // New file meta
     $imageMeta = new self();
     $imageMeta->fileUid = $originalMeta->fileUid;
     $imageMeta->folder = $originalMeta->folder;
     $imageMeta->fileMimeType = $originalMeta->fileMimeType;
     // Generate new file name
     $extension = pathinfo($originalMeta->fileName, PATHINFO_EXTENSION);
     $thumbFormat = $extension && $extension === 'png' ? 'png' : FileModule::getInstance()->thumbFormat;
     $imageMeta->fileName = pathinfo($originalMeta->fileName, PATHINFO_FILENAME) . '.' . $suffix . '.' . $thumbFormat;
     // Clone original file
     if (!copy($originalMeta->getPath(), $imageMeta->getPath())) {
         throw new FileException('Can not clone original file `' . $originalMeta->getRelativePath() . '` to `' . $imageMeta->getRelativePath() . '`.');
     }
     return $imageMeta;
 }