Results 1 to 13 of 13

Thread: is there an easy way to force download of a wmv file?

  1. #1
    I'm a farmhand on your dad's rooster ranch. haganxy's Avatar
    Join Date
    Dec 2004
    Location
    Seattle, WA
    Posts
    379

    is there an easy way to force download of a wmv file?

    this is what i want to do:

    we have a bunch of wmv movies in our member's area. we want the customer to be able to do a simple left mouse button click and have the movie be downloaded to their computer. however, the problem is that when they click on the "a href" link, the movie opens up in windows media player instead of popping up the box to confirm the download.


    this is my current solution:

    i have a CGI script that i'm passing the name of the wmv file to. the CGI script then reads in the wmv file, and then prints out the MIME header: Content-Type:application/x-download, along with the content to be downloaded.


    the current problem:

    way, way, way too CPU intensive. it's eating up all my juice.


    is there an easier solution?

    (i have thought about zipping up the wmv file into a zip file, but the problem is we are also streaming this video and we don't want to have a .wmv version AND .zip version of the same movie...it would take up too much hard drive space)
    hagan - IT nerd
    PrideBucks.com
    ICQ: 49962103


  2. #2
    virgin by request ;) Chilihost's Avatar
    Join Date
    Oct 2003
    Posts
    4,496
    you can set the options in your server's httpd.conf file to not stream any wmv files, but if you want to keep the streaming videos as well this will not work for you. You might be able to do it with htaccess files, if the video downloads were placed in a separate directory from the streaming videos. Is that possible or do you want to offer these movies as streams as well as downloads?

    cheers,
    Luke


  3. #3
    I'm a farmhand on your dad's rooster ranch. haganxy's Avatar
    Join Date
    Dec 2004
    Location
    Seattle, WA
    Posts
    379
    the problem is we want to be able to stream AND make the movie available for download.

    we want it so in the members area, it's something like this:

    download movie click here
    stream movie click here
    hagan - IT nerd
    PrideBucks.com
    ICQ: 49962103


  4. #4
    virgin by request ;) Chilihost's Avatar
    Join Date
    Oct 2003
    Posts
    4,496
    hrmmm....nope I don't know how to do that, sorry!

    cheers,
    Luke


  5. #5
    curiousbunny
    Guest
    Have them right click the link and select Save Target As :extat:


  6. #6
    virgin by request ;) Chilihost's Avatar
    Join Date
    Oct 2003
    Posts
    4,496
    i have been thinking about this and I do recall seeing a site that did this, unfortunately I have no idea where it is now.....but I do know they used some php code to do it, so if the surfer clicked "watch" they would send it thru a php script to force the video to be streamed, or if they selected "download" it would go thru a different php script to force it to be downloaded.

    unfortunately I have no idea what that php code is, but it **can** be done....any php experts around?

    cheers,
    Luke


  7. #7
    AusCoding Allan
    Guest
    I challenged my programmer with this - not sure what he'll come up with

    Allan


  8. #8
    I'm a farmhand on your dad's rooster ranch. haganxy's Avatar
    Join Date
    Dec 2004
    Location
    Seattle, WA
    Posts
    379
    Quote Originally Posted by curiousbunny
    Have them right click the link and select Save Target As :extat:
    yes, this is always an option, however, most of our customers are not very computer literate. they don't know the difference between a "right" click and a "left" click. trying to get them to follow more than one instruction at a time is just useless.
    hagan - IT nerd
    PrideBucks.com
    ICQ: 49962103


  9. #9
    I'm a farmhand on your dad's rooster ranch. haganxy's Avatar
    Join Date
    Dec 2004
    Location
    Seattle, WA
    Posts
    379
    Quote Originally Posted by Chilihost
    i have been thinking about this and I do recall seeing a site that did this, unfortunately I have no idea where it is now.....but I do know they used some php code to do it, so if the surfer clicked "watch" they would send it thru a php script to force the video to be streamed, or if they selected "download" it would go thru a different php script to force it to be downloaded.

    unfortunately I have no idea what that php code is, but it **can** be done....any php experts around?

    cheers,
    Luke

    i "think" the php script you're talking about is doing the same thing that my CGI script is doing...it's reading in the movie and then displaying the MIME headers then pushing the data out again.
    hagan - IT nerd
    PrideBucks.com
    ICQ: 49962103


  10. #10
    curiousbunny
    Guest
    found this:

    Suppose you've written an ASP page that contains a link to a known MIME type, but you want the user to download the file instead of viewing it. Add the following to your script:
    Code:
    response.addHeader "content-disposition", "attachment;filename=filename.ext"

    Then substitute the actual filename and extension, and it's as good as done. When your users click on the link, they'll immediately see the download dialog box instead of the file's contents.


  11. #11
    Am I Bitter?...Absolutely nicedreams's Avatar
    Join Date
    Apr 2004
    Location
    Washington DC Metro
    Posts
    572
    Here is some php code that that is similiar to what you described the cgi code doing. Perhaps it is faster? Still a neat little script.

    download.php?f=hotboyjerkingoff.mpg

    PHP Code:
    <?php

    $f 
    $_GET['f'];

    dl_file($f);

    function 
    dl_file($file){

       
    //First, see if the file exists
       
    if (!is_file($file)) { die("<b>404 File not found!</b>"); }

       
    //Gather relevent info about file
       
    $len filesize($file);
       
    $filename basename($file);
       
    $file_extension strtolower(substr(strrchr($filename,"."),1));

       
    //This will set the Content-Type to the appropriate setting for the file
       
    switch( $file_extension ) {
         case 
    "pdf"$ctype="application/pdf"; break;
         case 
    "exe"$ctype="application/octet-stream"; break;
         case 
    "zip"$ctype="application/zip"; break;
         case 
    "doc"$ctype="application/msword"; break;
         case 
    "xls"$ctype="application/vnd.ms-excel"; break;
         case 
    "ppt"$ctype="application/vnd.ms-powerpoint"; break;
         case 
    "gif"$ctype="image/gif"; break;
         case 
    "png"$ctype="image/png"; break;
         case 
    "jpeg":
         case 
    "jpg"$ctype="image/jpg"; break;
         case 
    "mp3"$ctype="audio/mpeg"; break;
         case 
    "wav"$ctype="audio/x-wav"; break;
    //     case "mpeg":
    //     case "mpg":
    //     case "mpe": $ctype="video/mpeg"; break;
         
    case "mov"$ctype="video/quicktime"; break;
         case 
    "avi"$ctype="video/x-msvideo"; break;

         
    //The following are for extensions that shouldn't be downloaded (sensitive stuff, like php files)
         
    case "php":
         case 
    "htm":
         case 
    "html":
         case 
    "txt": die("<b>Cannot be used for "$file_extension ." files!</b>"); break;

         
    //Everything else not listed above would be force downloaded
         
    default: $ctype="application/force-download";
       }

       
    //Begin writing headers
       
    header("Pragma: public");
       
    header("Expires: 0");
       
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
       
    header("Cache-Control: public"); 
       
    header("Content-Description: File Transfer");
       
       
    //Use the switch-generated Content-Type
       
    header("Content-Type: $ctype");

       
    //Force the download
       
    $header="Content-Disposition: attachment; filename=".$filename.";";
       
    header($header );
       
    header("Content-Transfer-Encoding: binary");
       
    header("Content-Length: ".$len);
       @
    readfile($file);
       exit;
    }

    ?>

    Gay Amateur Paysites / Solo Twink Paysite
    Nice Dreams Cash
    http://www.nicedreamscash.com


  12. #12
    I'm a farmhand on your dad's rooster ranch. haganxy's Avatar
    Join Date
    Dec 2004
    Location
    Seattle, WA
    Posts
    379
    nicedreams,

    thanks for the PHP code. it looks like it's doing basically the same thing that my CGI script is doing. not sure if the PHP would be more load intensive or the CGI script...
    hagan - IT nerd
    PrideBucks.com
    ICQ: 49962103


  13. #13
    DukeNuke
    Guest

    Be carefull!

    Be carefull with those scripts.

    It is not hard to use a script like that to download the .htaccess, password files (that you find from .htaccess) and maybe even the server logs for some hosts. Show me your logs and i'll find your ccbill folder in 2 seconds, in another 5 i'll have your ccbill password file, hope it is encrypted!

    DukeNuke
    “Time to kick ass and chew bubble gum. Damn, all out of gum.”


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •