public function actionFileReplace()
    {
        $this->checkRouteAccess(self::PERMISSION_ROUTE);
        
        $fileId = Yii::$app->request->post('fileId', false);
        $pageId = Yii::$app->request->post('pageId', 0);
        Yii::warning('replace request for file id' . $fileId, __METHOD__);
        $raw = $_FILES['file'];
        /** @var $file \luya\admin\file\Item */
        if ($file = Yii::$app->storage->getFile($fileId)) {
            $newFileSource = $raw['tmp_name'];
            if (is_uploaded_file($newFileSource)) {
                
                // check for same extension / mimeType
                $fileData = Yii::$app->storage->ensureFileUpload($raw['tmp_name'], $raw['name']);
                
                if ($fileData['mimeType'] != $file->mimeType) {
                    throw new BadRequestHttpException("The type must be the same as the original file in order to replace.");
                }
                
                if (Storage::replaceFile($file->systemFileName, $newFileSource, $raw['name'])) {
                    foreach (StorageImage::find()->where(['file_id' => $file->id])->all() as $img) {
                        $removal = Storage::removeImage($img->id, false);
                    }
                    
                    // calculate new file files based on new file
                    $model = StorageFile::findOne((int) $fileId);
                    $fileHash = FileHelper::md5sum($newFileSource);
                    $fileSize = @filesize($newFileSource);
                    $model->updateAttributes([
                        'hash_file' => $fileHash,
                        'file_size' => $fileSize,
                        'upload_timestamp' => time(),
                    ]);
                    $this->flushApiCache($model->folder_id, $pageId);
                    return true;
                }
            }
        }
        
        return false;
    }