SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast nick04's Avatar
    Join Date
    Jan 2012
    Location
    It Depends
    Posts
    61
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Download button that redirects to another page

    Hello Everyone,

    I'm looking forward to create a download button that allows users to download .exe(setup) file from my website and after that and it redirects them to another page. For example, check out the download button of this site:

    freeopener*com

    Is there any way to do it on a HTML website?
    Get iPhone to Computer Transfer Tool - Transfer iPhone Files (Voice Memos,
    Music, Videos, Photos) to computer and vice versa with ease.

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,940
    Mentioned
    215 Post(s)
    Tagged
    12 Thread(s)
    Hi there,

    The site you link to first redirects you to the "after" page (with a "Click here if your download doesn't start" notice) , then it initiates the download.
    As far as I know, this is really the only way to do what you ask (reliably).

    Linking to the after page is simple:

    HTML Code:
    <a href="download.html">Click here to download your file</a>
    Starting the download can then be done using a meta refresh, which is supported in most browsers:

    HTML Code:
    <meta http-equiv="refresh" content="5;url=path_to_your_file/file.exe"/>
    HTH

  3. #3
    SitePoint Enthusiast nick04's Avatar
    Join Date
    Jan 2012
    Location
    It Depends
    Posts
    61
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    Thank you for your reply!

    There are links to different (.exe) setup files on my download page:

    iphone-to-pc . com/ download . html


    So I'm bit confused about where do I need to put this Meta Refresh Tag that downloads the appropriate setup file?
    Get iPhone to Computer Transfer Tool - Transfer iPhone Files (Voice Memos,
    Music, Videos, Photos) to computer and vice versa with ease.

  4. #4
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,940
    Mentioned
    215 Post(s)
    Tagged
    12 Thread(s)
    Hi,

    If you are dealing with multiple downloads, you will ideally need to write your "Success" page in PHP or some such similar language.

    All of the links on your download page would point to this "Success" page and would pass in the file they want to download as a parameter.

    Your links on the download page would look like this:

    HTML Code:
    <a href="success.php?file_name=file_1.exe">Click here to download file 1</a>
    <a href="success.php?file_name=file_2.exe">Click here to download file 2</a>
    <a href="success.php?file_name=file_3.exe">Click here to download file 3</a>
    Your success page would look like this:

    PHP Code:
    <?php
    if(isset($_GET['file_name'])){
      
    $download_path '/downloads/' $_GET['file_name'];
    } else {
      die(
    "Please don't load this page directly!");
    }
    ?>

    <!DOCTYPE HTML>
    <html>
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta http-equiv="refresh" content="5;url=<?php echo $download_path ?>"/>
        <title>Success!</title>
      </head>
      
      <body>
        <h1>Your download will begin shortly!</h1>
        <p>If it doesn't begin, <a href="<?php echo $download_path ?>">click here</a></p>
      </body>
    </html>
    This is a simple example to demonstrate the concept.

    In real life you will want to be very restrictive as to what you accept in this $_GET['file_name'], as you don't want people downloading random files off of your server.
    In your case, you only seem to be offering eight files as downloads, so you could even check for each of these individually.

    PHP Code:
    <?php
      
    if(isset($_GET['file_name'])){
        if (
    preg_match('/file_\d.exe/'$_GET['file_name'])){
          
    $download_path '/downloads/' $_GET['file_name'];
        } else {
          die(
    "Invalid filename!");
        }
      } else {
        die(
    "Please don't load this page directly!");
      }
    ?>
    Hope that helps.

  5. #5
    SitePoint Enthusiast nick04's Avatar
    Join Date
    Jan 2012
    Location
    It Depends
    Posts
    61
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hello

    Sorry for the late reply. I got the concept. Thanks Dave
    Get iPhone to Computer Transfer Tool - Transfer iPhone Files (Voice Memos,
    Music, Videos, Photos) to computer and vice versa with ease.

  6. #6
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can search on the Internet for "Dynamic Drive" - a lot of codes and tutorials..

  7. #7
    SitePoint Enthusiast nick04's Avatar
    Join Date
    Jan 2012
    Location
    It Depends
    Posts
    61
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by attosoft View Post
    You can search on the Internet for "Dynamic Drive" - a lot of codes and tutorials..
    Can I get the free beer too?
    Get iPhone to Computer Transfer Tool - Transfer iPhone Files (Voice Memos,
    Music, Videos, Photos) to computer and vice versa with ease.

  8. #8
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by nick04 View Post
    Can I get the free beer too?
    Verry funny.........

  9. #9
    Team SitePoint Bentheax's Avatar
    Join Date
    Feb 2013
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You'll probably be reasonably safe with the example given by Pullo, but something to keep in mind when coding this sort of downloader functionality with more general paths is the dreaded Directory Traversal Attack - this is where an attacker passes in a bunch of '../../../' that gives them free license to download any path your server has access to.


Bookmarks

Posting Permissions

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