Home > Blockchain >  Symfony 5: Error file not found when trying to view a file using <a>
Symfony 5: Error file not found when trying to view a file using <a>

Time:12-16

In my public folder there is a pdf folder in that there are many pdf's. I am using

<a href="/pdf/1.pdf" download="1.pdf"> 1</a>

So when any body clicks on 1 they will be able to download the file. I have even tried using asset to do but the problem that occurred is I can download on local host but can't download on actual server. It shows Failed-No file. For more information, I am using Nginx.

server {
        server_name xxx.xxx.com;
        root /var/www/xxx.xxx.com/public;
        index index.php;

        location / {
                try_files /index.php /index.php;
                include snippets/fastcgi-notry-php.conf;
                fastcgi_pass unix:/var/run/php/php-fpm.sock;
        }
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php-fpm.sock;
        }
location ~ \.css {
    add_header  Content-Type    text/css;
} 
location ~ \.js {
    add_header  Content-Type    application/x-javascript;
}

CodePudding user response:

As you can see from your config, there are exceptions for .css and .js file extensions, which are served as static files with an appropriate content-type. That's why you can see all your styles and js code. So obviously, you must also add there file extensions which you're going to serve as static files:

location ~ \.pdf {
    add_header  Content-Type    application/pdf;
}
  • Related