了解 CakePHP 3 如何提供静态图像

huangapple go评论57阅读模式
英文:

Understanding how CakePHP 3 is serving static images

问题

我有一张图片位于webroot/uploads/files文件夹中。这张图片由CakePHP静态提供。我试图更好地理解如何控制这个机制。我已经从我的应用程序和插件中删除了$routes->fallbacks(DashedRoute::class);的每个出现。因此,我的应用程序目前无法正常运行。然而,静态图片仍在提供。

我应该在哪里查找以防止提供静态图片?一旦我禁用它,我打算尝试创建一个控制器来更精细地控制它。

英文:

I have an image located in the webroot/uploads/files folder. This image is being served statically by CakePHP. I am trying to better understand how to control this mechanism. I have removed every occurrence of $routes->fallbacks(DashedRoute::class); from my app and plugins. My app therefor currently does not function. However, the static images are still being served.

Where should I be looking next to prevent the serving of static images? Once I have disabled it, I am going to try and create a controller to take care of it with more fine-grain control.

答案1

得分: 0

CakePHP不提供这些图像的服务。相反,它们由Apache web服务器提供。可以通过在适当的.htaccess文件中使用条目来停用这些图像的服务。

在我的情况下,我将以下代码添加到了CakePHP应用程序中webroot文件夹中的.htaccess文件中,该文件位于默认的Apache /var/www/html/目录结构中。

我使用以下代码停用了图像服务:

<Directory /var/www/html/app/webroot/uploads/files>
    Options -Indexes
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteRule ^.*$ - [R=404,L]
    </IfModule>
</Directory>
英文:

CakePHP is not serving these images. Instead they are being served by the Apache web server. The serving of these images can be deactivated by making use of of entries in the appropriate .htaccess file.

In my case I added the following code to the .htaccess file in the webroot folder inside of my CakePHP app, which is located in the default Apache /var/www/html/ directory structure.

I deactivated image serving with the follow code:

&lt;Directory /var/www/html/app/webroot/uploads/files&gt;
    Options -Indexes
    &lt;IfModule mod_rewrite.c&gt;
        RewriteEngine On
        RewriteRule ^.*$ - [R=404,L]
    &lt;/IfModule&gt;
&lt;/Directory&gt;

huangapple
  • 本文由 发表于 2023年6月27日 18:23:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76563901.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定