在 zend 框架中设置虚拟主机后,项目图像不可见
我的项目结构如下 ---
/
公开
- .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为公共文件夹中的
data
文件夹创建符号链接(因为这是可供公众访问的文档根目录)。运行以下命令:
确保“apache”用户可以访问上述
data/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:
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:
要传递存储在 Web 根目录之外的文件夹中的图像,您可以使用
getAction()
方法创建一个ImageController
,该方法:当然,您需要添加一条将这些图像 url 映射到此控制器/操作的路由。
@Sahal 的符号链接想法可能更好,因为它不需要另一个完整的调度周期来传递本质上只是静态内容。但是,如果您的主机以某种方式不允许您进行符号链接,那么这可以作为一种解决方法,尽管不可否认,这是一种性能较差的方法。
To deliver images that are stored in a folder outside the web root, you could create an
ImageController
with agetAction()
method that: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.