How can i add a form where you enter a code to download something?

Discussion in 'Programming' started by diego018, Jan 26, 2012.

  1. #1
    i want to add a form in a website (or in a wordpress page if there's a plugin) where there is a form where you enter a code (Example deJ9845) and click download and you download a file.

    is this difficult?
    anyone can help me ? thanks !
     
    diego018, Jan 26, 2012 IP
  2. dany3l89

    dany3l89 Active Member

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    96
    #2
    $code="deJ9845";
    $file="file.txt";
    $file_download = basename($file);
    if(isset($_POST['submit'])){
        $code_input = $_POST['code'];
        if($code_input==$code){
            header ("Content-Type: application/octet-stream");
            header ("Accept-Ranges: bytes");
            header ("Content-Length: ".filesize($file));
            header ("Content-Disposition: attachment; filename=".$file_download);
            readfile($file);
            exit; 
        }
    }
    PHP:
    <form action="" method="post" >
    <input type="text" name="code" />
    <input type="submit" name="submit" value="Download" />
    </form>
     
    dany3l89, Jan 29, 2012 IP
  3. karlene

    karlene Guest

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hello

    No this is not hard at all.

    All you need to do is get the code from wherever it's made e.g. aweber and then choose a place on your page where you want to put it.

    You have to do so in the source code. If you're using wordpress click on the HTML tab and you will see the coding.

    Hope that helps.

    Karlene
     
    karlene, Jan 30, 2012 IP