Mime-type of downloading file

后端 未结 2 1447
死守一世寂寞
死守一世寂寞 2020-12-18 14:25

i\'m trying to create downloadable video-files. In my site there is a list of files. All videos are in .flv-format (flash). There is exact link to the file for the all video

相关标签:
2条回答
  • 2020-12-18 15:04

    The recommended MIME type for that is application/octet-stream:

    The "octet-stream" subtype is used to indicate that a body contains arbitrary binary data. […]

    The recommended action for an implementation that receives an "application/octet-stream" entity is to simply offer to put the data in a file, with any Content-Transfer-Encoding undone, or perhaps to use it as input to a user-specified process.

    0 讨论(0)
  • 2020-12-18 15:06

    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);
    
    ?>
    

    Set $filepath to the path of the file to be downloaded, and set Content-Type to the mime type of the file being downloaded.

    Point 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 as specified above, and point the "download" link to this page with a GET parameter named "filepath" containing the file path.

    For example, if you name this php file "download.php", point the download link for a file named "movie.mov" (in the same directory as download.php) to "download.php?filepath=movie.mov".

    0 讨论(0)
提交回复
热议问题