Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11

Thread: Download Button

  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Location
    Scotland
    Posts
    134
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Download Button

    Hi Guys,

    i currently use a basic link of text so users can down files like so:

    PHP Code:
    <a href="download.php?id='.$id.'"><font color="red" size="5"'.$file_name.' </font
    but i was wanting to make it an actual button i have tried this below but no joy

    PHP Code:
    <form action="download.php?id='.$id.'"><input type="submit" value="Download"></form
    can anyone give me some advice on how to do it correctly.

    thanks guys

    Graham

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Can I ask why you want this a button?
    Code:
    <form action="download.php?id='.$id.'"><input type="submit" value="Download"></form>
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder
    Join Date
    Jul 2007
    Location
    Scotland
    Posts
    134
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Hi,

    well SOME people don't know how to use the link believe it or not lol if the button is staring them in the face there no 2 ways about it.

    Graham

  • #4
    Regular Coder
    Join Date
    Jan 2007
    Posts
    217
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by graham23s View Post

    PHP Code:
    <?php
     
    echo"<form action='download.php?id='{$id}'><input type='submit' value='Download'></form>";
    ?>
    That should fix it =X

  • #5
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,146
    Thanks
    2
    Thanked 333 Times in 325 Posts
    graham23s, your <form action="download.php?id='.$id.'">... will work if you add a method="post" to the <form ... tag. The default method is GET when no method is specified and the form will overwrite your ?id= parameter.

    Short version - the only way to have a GET parameter in the action="..." is if you specify method="post".
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #6
    Regular Coder
    Join Date
    Jul 2007
    Location
    Scotland
    Posts
    134
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Hi Guys,

    when i do this:

    PHP Code:
    echo "<form method=\"POST\" action='download.php?id='$id'><input type='submit' value='Download'></form>"
    but the id is missing the bit i need lol

    is that right what i have done above?

    thanks guys

    Graham
    Last edited by graham23s; 07-24-2007 at 12:11 AM.

  • #7
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    PHP Code:
    <form action="download.php" method="get">
    <input type="hidden" name="id" value="<?php echo $id?>">
    <input type="submit" value="Download">
    </form>
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #8
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,146
    Thanks
    2
    Thanked 333 Times in 325 Posts
    Edit: I see you edited your post and put in the code. There is an extra single-quote that is stopping the output.

    You would need to post your actual code that echos the <form... to the browser.

    The partial code you posted in the first post in this thread has the potential of a quoting problem and if you used ole90's posted code, it has an extra single-quote that would prevent it from working.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #9
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    graham23s, your <form action="download.php?id='.$id.'">... will work if you add a method="post" to the <form ... tag. The default method is GET when no method is specified and the form will overwrite your ?id= parameter.
    Actually, it won't. Do a POST with a variable in the URL, you will see all values present in $_REQUEST.

    There's nothing wrong with doing it that way.

  • #10
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    This would also work
    PHP Code:
    echo "<form action=\"download.php?id=$id\" method=\"post\"><input type=\"submit\" value=\"Download\"></form>"
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #11
    Regular Coder
    Join Date
    Jul 2007
    Location
    Scotland
    Posts
    134
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Thanks a ton guys i got it workin perfectly

    thanks again

    Graham


  •  

    Posting Permissions

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