Download Dialog Window

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ProMorpher
Forum Newbie
Posts: 1
Joined: Mon Oct 11, 2004 6:10 pm

Download Dialog Window

Post by ProMorpher »

feyd | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


I had found a script on the web a few months back, but don't know how to implement it. It is suppose to pop-up the Download Dialog Window (Open/Save As options) when a visitor to my site clicks on one of the downloadable videos. I have the following code in a file called download.php and was wondering what I need to put on the index page to call that code. Thanks.

Code: Select all

<?php
     if ($_REQUEST ['getfile']){
        $file = $_REQUEST ['getfile'];
     } else {
       $file = "..";
     }

     if(strstr($file, "..")){
                      Header( "Content-Type: text/html");
                      echo ('
                           <html><head><title>Error</title></head><body>
                           <h3>Invalid characters in filename.</h3>
                           </body></html>
                      ');
     } else if(!file_exists($file) || !is_readable($file)){
       Header ("Content-Type: text/html");
       echo ('
            <html><head><title>Error</title></head><body>
            <h3>The file you requested does not exist.</h3>
            </body></html>
       ');
     } else {
       Header ("Content-Type: audio/wma");
       Header ("Content-Length: ".filesize($file));
       Header ("Content-Disposition: attachment; filename=$file");
       Header ("Content-Description: Windows Media Audio File");
       readfile($file);
     }
?>

figured it out


feyd | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

-

Well, you need a form with an input field, where the user may enter the path/name of the file.
Beware of putting this script in folders including files you do NOT want to be downloadable (also other folders in this download-area! (./).
Since this script takes real filenames, it's very unsecure when used in the wrong way!


Then the user submits the form ito the given php, which pops up a download window, if the path/filename exists.


djot
-
Post Reply