如何阅读图像从一个文件夹htaccess文件文件夹、图像、文件、htaccess

2023-09-02 01:10:58 作者:房东的猫

我使用ReadFile函数来读取图像文件。它的工作原理,在大多数情况下,除非图像位于与htaccess文件的目录。

I am using the readfile function to read image files. It works in most cases except when an image is located in a directory with htaccess file.

下面是一个例子:

header("Content-type: image/jpeg");
ob_clean(); // clean output buffer
flush(); // flush output buffer 
readfile("http://127.0.0.1/WebProjects/project1/data/media/images/original/7.jpg");
exit;

.htaccess中位于 http://127.0.0.1/WebProjects/project1/ 目录,看起来是这样的:

The htaccess is located in the http://127.0.0.1/WebProjects/project1/ directory and looks like this:

RewriteEngine On

RewriteRule ^.htaccess$ - [F]

RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]

RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]

RewriteRule ^public/.*$ /public/index.php [NC,L]

什么办法如何解决这个问题? htaccess的文件必须在那里,因为该文件夹中的Web应用程序需要它的工作。

Any way how to get around this? The htaccess file must be there because the web application in that folder needs it to work.

推荐答案

为什么不直接从文件系统而不是通过Web服务器读取文件?

Why not read the file directly from the filesystem instead of going through the web server?

readfile("/srv/WebProjects/project1/data/media/images/original/7.jpg");