0

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

2 Answers2

3

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...">
Rakesh Sankar
  • 9,337
  • 4
  • 41
  • 66
Sahal
  • 4,046
  • 15
  • 42
  • 68
  • is there any different way to access it using some apache configuration. – user802697 Jun 17 '11 at 05:49
  • @user802697 I doubt you can do it just like that. But yes, you can, that will require another .php file to display your images - [image display](http://www.wallpaperama.com/forums/how-to-display-pictures-or-image-with-php-file-script-showing-how-to-link-photo-with-php-file-t1344.html) – Rakesh Sankar Jun 17 '11 at 09:14
  • @user802697: if you don't want links on the filesystem use the Alias command in apache to associate some url to a physical directory (which can be outside webroot) alias /myuploaded /var/www/toletbd/data/uploads – regilero Jun 17 '11 at 14:35
1

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.

David Weinraub
  • 14,144
  • 4
  • 42
  • 64