开发者

After setting up virtual host in zend framework project image are not visible

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 d开发者_运维技巧irectory.
  • 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


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...">


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜