Mime type of download file

I am trying to create downloadable video files. My site has a list of files. All videos are in .flv (flash) format. There is an exact file link for all videos. But in all browsers, after clicking on the contents, the browser window is loaded. I do not need this. As I understand it, I have to create a redirect page that contains the mime type of the download file. What should I do? Language: php

+2
source share
2 answers

Create a PHP page with the following:

<?php $filepath = "path/to/file.ext"; header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=$filepath"); header("Content-Type: mime/type"); header("Content-Transfer-Encoding: binary"); // UPDATE: Add the below line to show file size during download. header('Content-Length: ' . filesize($filepath)); readfile($filepath); ?> 

Give $filepath path to the file to be uploaded and set the Content-Type to the mime type of the uploaded file.

Send the download link to this page.

For multiple files of the same type:

 <?php $filepath = $_GET['filepath']; header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=$filepath"); header("Content-Type: mime/type"); header("Content-Transfer-Encoding: binary"); // UPDATE: Add the below line to show file size during download. header('Content-Length: ' . filesize($filepath)); readfile($filepath); ?> 

Replace the information above and specify the “download” link to this page with the GET parameter named “file path” containing the file path.

For example, if you name this php file “download.php”, specify the download link for the file named “movie.mov” (in the same directory as download.php) to “download.php? Filepath = movie. mov ".

+7
source

Recommended MIME type for this application/octet-stream :

The octet stream subtype is used to indicate that the body contains arbitrary binary data. [...]

The recommended action for the implementation that receives the application / octet stream object is simply to suggest placing the data in a file, while any Content-Transfer-Encoding encoding is canceled, or perhaps use it as an input to the user process.

+9
source

Source: https://habr.com/ru/post/920882/


All Articles