How to allow flash video download?

Discussion in 'Web Design and Development' started by Macman1993, Jul 23, 2009.

  1. Macman1993 macrumors 6502

    Macman1993

    Joined:
    Nov 23, 2007
    #1
    How do I allow users to download flash video on my website? I know that I can put the .flv file into a .zip file and just link to it but I don't like that way. How can I allow downloading of the actual .flv file? If I have an flv video available for watching on my site I would like to be able to just link to that .flv file instead of uploading a second .flv file in a .zip file and letting people download that?
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
  3. Macman1993 thread starter macrumors 6502

    Macman1993

    Joined:
    Nov 23, 2007
    #3
    Sounds like it would work only problem is I don't know PHP at all. This is the code the website gave me. Can someone edit the code just to make me understand it. I.E. put "Video link here" where the video link should be and if this is the kind of code that will just download any .flv file can you edit it that way for me. Sorry I don't know what I'm talking about I haven't studied PHP yet.
     
  4. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    Here's the entire PHP file to create (we'll call it dlFile.php here),
    PHP:
    <?
    if (isset(
    $_GET['file'])) {
      
    force_download($_GET['file']);
    }
    function 
    force_download($file) {
      
    $dir 'path/to/file/';
      
    // Ensure file request was sent, that the file exists, and it's a FLV file
      
    if (isset($file) && file_exists($dir.$file)
          && 
    preg_match('/\.flv$/'$file)) {
        
    header('Pragma: public');
        
    header('Expires: 0');
        
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        
    header('Cache-Control: public');
        
    header('Content-type: application/force-download');
        
    header('Content-Disposition: inline; filename="' $dir.$file '"');
        
    header('Content-Transfer-Encoding: Binary');
        
    header('Content-length: '.filesize($dir.$file));
        
    header('Content-Type: application/octet-stream');
        
    header('Content-Disposition: attachment; filename="' $file '"');
        
    readfile("$dir$file");
      } else { echo 
    'Bad file request!'; }
    }
    ?>
    Then, in your web page when you want to put in a link to download a FLV file we'll set it up like so.

    HTML:
    <a href="dlFile.php?file=cool.flv">Cool FLV</a>
    That assumes you named the PHP file from the above code dlFile.php and you have a FLV file named cool.flv.

    Again, this is untested code. I don't have any FLV files. I'm not sure if it's considered a binary file or not. I've generally just used this on PDF files. I also made some adjustments to the code on that link, merging some of my own code that I used for this.
     
  5. Macman1993 thread starter macrumors 6502

    Macman1993

    Joined:
    Nov 23, 2007
    #5
    Hmm didn't work. Try it yourself because I'm sure you can make much more sense of what its telling me as a response.

    www.clm51193.com/index.html
     
  6. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #6
    Might know, looks like I forgot the php after the <? at the very top,

    PHP:
    <?php
    if ...
    Though, with the error message, it looks like it's interpreting it as PHP, but go ahead and try adding that to see if it makes a difference.

    Edit: Also, I didn't make this explicit before, but the line for $dir inside the function needs to be updated for the path to the file. It looks like the file is inside the same folder so you can change that line to,
    PHP:
    $dir '';
    I tested the script with the flv file you're using and it did work for me so with the two changes mentioned in this post it should work fine.
     
  7. SrWebDeveloper macrumors 68000

    SrWebDeveloper

    Joined:
    Dec 7, 2007
    Location:
    Alexandria, VA, USA
    #7
    I use this code which does the job nicely across all browsers, notice the headers that are set:

    Notes:
    $DownloadName is the filename.ext only - hide the path from users
    $Filename is full /path/to/filename.ext on server

    PHP:
    header("Content-Disposition: attachment; filename=\"{$DownloadName}\"");
            
    header("Cache-Control: cache, must-revalidate");    
            
    header("Pragma: public");
            
    header('Content-Type: application/force-download');
            
    header('Content-Type: application/octet-stream');
            
    header('Content-Type: application/download');
            
    header('Content-Description: File Transfer');    
        
          
    // open input file
          
    $hFPi fopen ("$FileName""rb");
          if (
    $hFPi == FALSE) {
              die (
    "Can't open file {$FileName}");
              } 
    /* endif */

          // sent third header line with file size
          
    header("Content-Length: " filesize($FileName));

          
    // now sent data
          
    while (!feof($hFPi)) {
              
    $sBuf fread ($hFPifilesize($FileName) );
              echo 
    $sBuf;
          } 
    /* endwhile */

          // close input file
          
    fclose ($hFPi);
     

Share This Page