skip to Main Content

I have a short video sharing website. The user can download video from there. I’m facing some problem now. I want the user to download the video directly but when users visit my link browser auto-playing the video.

I only want when user click on link Video download will start auto.

Now I’m sharing video link like this
Example: www.example.com/examle.mp4

Please give me suggestion

3

Answers


  1. Chosen as BEST ANSWER

    Thank you guys for answering. I want my URL to make direct downloadable. You guys are suggesting me for php file but i found a solution online. This work.

    I just need to put this code on .htaccess

    <FilesMatch ".(mp4|MP4)">
      ForceType application/octet-stream
      Header set Content-Disposition attachment
    </FilesMatch>

    This works perfectly.

    Thank you Guys


  2. <?php
    $file = "www.example.com/examle.mp4"; 
    
    header("Content-Description: File Transfer"); 
    header("Content-Type: application/octet-stream"); 
    header("Content-Disposition: attachment; filename='" . basename($file) . "'"); 
    
    readfile ($file);
    exit(); 
    ?>
    
    Login or Signup to reply.
  3. instead of linking to the video file directly you could link to a php file which does trigger the download for you.

    <?php
      header('Content-disposition: attachment; filename=movie.mp4;');
      header('Content-Length: '. filesize('movie.mp4'));
      readfile('movie.mp4');
      exit;
    

    With .htaccess you could redirect the mp4 link to your php file.

    RewriteEngine on
    RewriteRule ^movie.mp4$ ./movie.php
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search