]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Отдача файлов
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 12 Sep 2025 12:36:16 +0000 (15:36 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 12 Sep 2025 12:36:16 +0000 (15:36 +0300)
erp24/media/config/media.config.php
erp24/media/controllers/FlowwowController.php

index f4b3eba97bb11365e3b2182f11696cc3abc8bc84..38dba6ff890809be5373f1a41cf5f8075fe58633 100644 (file)
@@ -97,7 +97,7 @@ return [
         '@npm' => '@vendor/npm-asset',
         '@dist' => '@app/dist',
         '@uploads' => "@yii_app/uploads",
-        '@feeds' => '@app/media/feeds',
+        '@feeds' => '@app/feeds',
     ],
     'params' => require dirname(__DIR__, 2) . '/config/params.php',
     'timeZone' => 'Europe/Moscow',
index 18d2db5c3fbdc9e022a60d49f33e4b3d6cc3cbe7..04b0d0766f76c14f906b87aff9e91b0eb8693ac7 100644 (file)
@@ -27,14 +27,27 @@ class FlowwowController extends Controller
      */
     public function actionFeed($id)
     {
-        $dir = Yii::getAlias('@feeds');
-        $matches = glob($dir . DIRECTORY_SEPARATOR . "feed_{$id}.xml") ?: [];
-        if (!$matches) {
-            throw new \yii\web\NotFoundHttpException('Фид ещё не сгенерирован');        }
+        $id = (int)$id;
+
+        $dir  = Yii::getAlias('@feeds');
+        $path = $dir . DIRECTORY_SEPARATOR . "feed_{$id}.xml";
+
+        if (!is_file($path)) {
+            Yii::error([
+                'msg'     => 'feed not found',
+                'alias'   => '@feeds',
+                'dir'     => $dir,
+                'dirReal' => @realpath($dir),
+                'path'    => $path,
+                'exists'  => file_exists($path),
+            ], __METHOD__);
+
+            throw new \yii\web\NotFoundHttpException('Фид ещё не сгенерирован' . $dir);
+        }
 
-        return Yii::$app->response->sendFile($matches[0], basename($matches[0]), [
+        return Yii::$app->response->sendFile($path, "feed_{$id}.xml", [
             'mimeType' => 'application/xml; charset=utf-8',
-            'inline' => true,
+            'inline'   => true,
         ]);
     }