Getting NotFoundHttpException when accessing a image file in uploads directory in Laravel 5.1

2.3k Views Asked by At

My setup

  • WAMP
  • Windows 8

I have an uploads directory in

  • iapp <- Root Directory
    • uploads
    • app
    • public

Virtual Hosts file (httpd-vhosts.conf)

NameVirtualHost *:80

    <VirtualHost *:80>
        DocumentRoot C:/wamp/www/
        ServerName localhost
    </VirtualHost>

    <VirtualHost *:80>

        ServerAdmin [email protected]
        DocumentRoot "C:/wamp/www/iapp/public" 
        ServerName iapp.dev
        ErrorLog "logs/iapp.dev-error.log"
        CustomLog "logs/dev-iapp.dev-access.log" common

        <Directory "/">
            Order Deny,Allow
            Deny from all
            Allow from 127.0.0.1
        </Directory>

    </VirtualHost>

my htaccess file inside public diretory

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    # RewriteRule ^(.*)/$ /$1 [L,R=301]

    #RewriteCond %{REQUEST_URI} !^
    #RewriteRule ^(.*)$ /$1 [L]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

My App is working fine but I can't access any images/files inside my uploads directory.When accessing an image or file it is throwing me this error

NotFoundHttpException in C:\wamp\www\iapp\vendor\laravel\framework\src\Illuminate\Routing\RouteCollection.php line 142:

How do I solve this? And I also want to know which is the best place to put file uploads?

thank you!

1

There are 1 best solutions below

4
Mike Rockétt On BEST ANSWER

You cannot access directories and files that are above the document root, that is public. You need to move your uploads directory to the public directory.