Charm_quark
Charm_quark

Reputation: 386

Missing file extension on download from header

i'm using the below code to download a file, which work's well but the problem is that the file extension is missing, even after stressful download . i have tried changing it to other MIME types, what could be the problem and how do i solve it ?

header('Content-Type: audio/mp3');
header("Content-Disposition: attachment; filename=$row[3]");
header("Content-Length: ".filesize("$row[1]$row[2]"));
$fp = fopen("$row[1]$row[2]", "r");
fpassthru($fp);
fclose($fp);

NOTE: the values in the $row array are fine.

Upvotes: 2

Views: 2673

Answers (3)

zawhtut
zawhtut

Reputation: 8541

Abit modification on Patrick answer

header("Content-Disposition: attachment; filename="."\"{$fname}\"");

Upvotes: 0

Toverbal
Toverbal

Reputation: 256

Just a shot in the dark here, could it be that the filename has a space in it? In that case you can try to add double quotes around the filename, there are reports about parts after a space being omitted (e.g. here: http://kb.mozillazine.org/Filenames_with_spaces_are_truncated_upon_download)

Edit: As discussed in the comments, the headers did not return the extension, so adding the .mp3 extension manually in the back-end solves this problem.

Upvotes: 6

Patrick Kostjens
Patrick Kostjens

Reputation: 5105

You might try adding escaped quotes around the filename like this:

header("Content-Disposition: attachment; filename=\"$row[3]\"");

Upvotes: 0

Related Questions