Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

bobbybouwmann's avatar

Response download not working on Server

Hi guys,

So I'm working on a project where users can upload big images and where the admins can view those images and download them as well.

The problem is that this works fine locally, but on my server (managed with Forge) it's not working. The viewing part is working fine, but the download part isn't.

It probably related to the download problem, but when I view the image in the browser (which is working fine) and when I try to download the file with my right mouse button I get a failed exception from Chrome as well that the file is invalid to download

It sounds to me like it is a permission issue or something else, but I can't find any solution to the problem so far.

The viewing part is working fine using the following code.

public function show($filename);
{
    $path = storage_path($filename);

    return response()->file($path);
}

Now the download part is done like so

public function download($filename)
{
    $path = storage_path($filename);

    $headers = array('Content-Type' => File::mimeType($path));

    return response()->download($path, $filename, $headers);
}

If you need more information let me know ;) Any feedback or help would be appreciated!

0 likes
14 replies
Thijmen's avatar

You are saying that you can view the image in Chrome, but you cannot download? Seems to me something wrong with Chrome. You tried any other browser or try to CURL it?

bobbybouwmann's avatar

So to verify, downloading the file from viewing the file works fine on others browser (tested firefox and safari).

However the download part is still nog working. I get the following message from firefox

File not found. Firefox can't find the file at https://example.com/file.jpeg

The message is weird since the file exists when I view it..

bashy's avatar

Best to try with cURL first. See what type of response you get.

Thijmen's avatar

Or you can try and see if Wireshark gives you more information, so you don't have to debug CURL :)

bobbybouwmann's avatar

So I tried it out with curl and that works just fine!

curl -O https://example.com/file.jpeg

When I open the downloaded file it's the same image and in full quality, so with curl it's working fine!

If it's helpful, this is what curl shows me

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1256k  100 1256k    0     0   916k      0  0:00:01  0:00:01 --:--:--  916k
bashy's avatar

Yeah you can see with -vI (upper i) to see HEAD info etc :) but if the file is there, must be something related to browsers then (which is what I wanted to exclude).

bobbybouwmann's avatar
bobbybouwmann
OP
Best Answer
Level 88

It must be chrome I guess. If I do the same action in Safari it works fine! It just downloads the file and gives zero errors.

Now for the extra info. My curl command does show a 404 when downloading the file. However the files is downloaded correctly

< HTTP/1.1 404 Not Found
< Server: nginx/1.9.9
< Content-Type: image/jpeg
< Content-Length: 1286256
< Connection: keep-alive
< Cache-Control: public
< Last-Modified: Wed, 03 Aug 2016 10:03:14 GMT
< Content-Disposition: attachment; filename="urenbriefje.jpg"
< Accept-Ranges: bytes
< Date: Mon, 08 Aug 2016 08:25:17 GMT
kumarmann's avatar

Hello dears can you tell me here i have 3 table like as user table ,test table ,demo table . And user table field look like as user_id , name ,title ect. And test table look like as test_id ,title , user_id etc. and demo like as id ,user_id etc. i want to edit the data from test or demo table then here user_id should be in dropdown and show user_id in user_id field.\please tell me how i do it.please tell me procedure for view ,controller,model relation for this .

kumarmann's avatar

Hello dears can you tell me here i have 3 table like as user table ,test table ,demo table . And user table field look like as user_id , name ,title ect. And test table look like as test_id ,title , user_id etc. and demo like as id ,user_id etc. i want to edit the data from test or demo table then here user_id should be in dropdown and show user_id in user_id field.\please tell me how i do it.please tell me procedure for view ,controller,model relation for this .

ohffs's avatar

Well, that's almost impressive... o_O

1 like
bobbybouwmann's avatar

@ohffs It really is!!

@kumarmann Create a new thread, we won't help you in my thread... Thanks for making this thread really unclear now!!

schuyler.bos's avatar

@bobbybouwmann did you ever solve this issue? i'm having the same problem, on my production server I receive a 404 response when using the download() response. It's weird because it downloads via CURL just fine even though I receive the 404. However, on my local machine, I get a 200 status code and everything works just fine in any browser.

It has to be an environment problem but I can't figure out what it is. Curious where you left this?

chopin's avatar

I had the same issue downloading Excel files when using maatwebsite/laravelexcel package. Scratched my head for a while till I looked at laravel.log file. It had the error

ERROR: Class 'ZipArchive' not found

So I installed php-zip ext. Always ensure all your required PHP extensions are in place. Always check the Laravel error log for these sneaky issues.

Please or to participate in this conversation.