在 zend 框架中设置虚拟主机后,项目图像不可见

发布于 2024-11-15 21:10:27 字数 1185 浏览 3 评论 0原文

我的项目结构如下 ---

  • /

    • 公开

      • .htaccess
      • index.php
      • 模板............
    • 数据

      • 上传(此应用程序上传的所有图像)
      • ............

良好

在为该项目设置虚拟主机之前,一切都运行 但设置后我无法在任何地方看到上传的图像。

我可能会因为以下原因发生这种情况:

  • 我的虚拟主机指向公共目录,但上传的图像位于上传目录下。
  • 我的问题是,在不将上传目录更改为公共目录的情况下,我如何能够显示我的图像

以下是我的 .htaccess 文件 ----------

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

和 apache 文件主机设置如下 ------ - -

<VirtualHost 192.168.0.3:80>
   DocumentRoot "/var/www/toletbd/public"
   ServerName hometolet.local

   # This should be omitted in the production environment
   SetEnv APPLICATION_ENV development

   <Directory "/var/www/toletbd/public">
       Options Indexes MultiViews FollowSymLinks
       AllowOverride All
       Order allow,deny
       Allow from all
   </Directory>

</VirtualHost>

谢谢 鲁兹迪

My project structure is like following ---

  • /

    • public

      • .htaccess
      • index.php
      • template ...........
    • data

      • uploads (all the uploaded image by this application)
      • .....................

like these

before setting up virtual host for this project alls are working good but after setting up i can not able to see the uploaded images anywhere.

I might be happening for following reason

  • my virtual host pointing public directory but uploaded images are under uploads directory.
  • my question is that without changing the uploads directory to public directory how can i able to show my images

Followin is my .htaccess file ----------

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

and on apache file host setting is as following---------

<VirtualHost 192.168.0.3:80>
   DocumentRoot "/var/www/toletbd/public"
   ServerName hometolet.local

   # This should be omitted in the production environment
   SetEnv APPLICATION_ENV development

   <Directory "/var/www/toletbd/public">
       Options Indexes MultiViews FollowSymLinks
       AllowOverride All
       Order allow,deny
       Allow from all
   </Directory>

</VirtualHost>

Thanks
Ruzdi

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眉黛浅 2024-11-22 21:10:27

为公共文件夹中的 data 文件夹创建符号链接(因为这是可供公众访问的文档根目录)。

运行以下命令:

cd /var/www/toletbd/public
ln -nfs /var/www/toletbd/data/images 图像

确保“apache”用户可以访问上述 data/images 文件夹,否则您将收到权限被拒绝的错误。

现在,您可以像这样使用它:

<img src="/images...">

Create a symbolic link for data folder inside your public folder (since this is your document-root which is accessible to public.

Run this command:

cd /var/www/toletbd/public
ln -nfs /var/www/toletbd/data/images images

Make sure, the above data/images folder is accessible to "apache" user otherwise you will get a permission-denied error.

Now, you can use it something like this:

<img src="/images...">
夏花。依旧 2024-11-22 21:10:27

要传递存储在 Web 根目录之外的文件夹中的图像,您可以使用 getAction() 方法创建一个 ImageController,该方法:

  1. 在文件夹中查找图像
  2. 设置响应中适当的 mime 类型标头
  3. 执行 readfile() 来传送内容。

当然,您需要添加一条将这些图像 url 映射到此控制器/操作的路由。

@Sahal 的符号链接想法可能更好,因为它不需要另一个完整的调度周期来传递本质上只是静态内容。但是,如果您的主机以某种方式不允许您进行符号链接,那么这可以作为一种解决方法,尽管不可否认,这是一种性能较差的方法。

To deliver images that are stored in a folder outside the web root, you could create an ImageController with a getAction() method that:

  1. Looks for the image in the folder
  2. Sets the appropriate mime-type headers in the response
  3. Performs a readfile() to deliver the content.

Of course, you would need to add a route that maps those image urls to this controller/action.

@Sahal's symlink idea is probably better, since it doesn't require another full dispatch cycle to deliver what is essentially just static content. But if your hosting somehow doesn't allow you to symlink, then this could serve as a workaround, though an admittedly less-performant one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文