Reputation: 11830
I am working on a project where I need a download feature for videos, as of now my download code is below
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=".$fileName);
header("Content-Type: video/mp4");
header("Content-Type: video/webm");
header("Content-Type: video/flv");
header("Content-Transfer-Encoding: binary");
readfile($downloadUrl);
The above code works fine. But the thing is my file format can be any type for eg. .flv, .mp4,.3gp.
So, My question is the above code requires to pass Content-Type for each type. Is there a generic Content-Type that I can pass which supports all file formats.
Upvotes: 2
Views: 779
Reputation: 111219
Yes: application/octet-stream
. If you're not interested in opening the file this mime type tells the browser the file is of some unspecified type and can only be saved to disk.
Upvotes: 3
Reputation: 37365
In common case you can use just
header('Content-type: application/octet-stream')
Sending specific content-type just helps client to understand what application should be used to open incoming file. Since you're sending content-disposition attachment, there is no need to open a file.
Upvotes: 4