In php how do you set a <a href > </a> link to download a file to the user.

example

<a href="download temp.zip file" > </a>
when it is click

the download location is store in mysql database.

please and thank you

    <?
    echo "<a href='file.exe'>Download Now!</a>";
    ?>

      First you need a link page:

      //Start link page
      <html><body>
      <a href="download.php?file=<?= $file ?>" target="newwindow">File to download</a>
      </body></html>
      //End link page
      
      //Start download page
      <?
      $file = $HTTP_GET_VARS['file'];
      header("Location: $file");
      ?>
      

      All freehanded, no promises to works off hand, that is just an example.

        This is the code i'm trying :

        while ($a = current($taskInst->attachments)) {
        $attachment = new attachment($a);
        echo "<a href=\"javascript:openwindow('".$config['attach_url']."/".$attachment->created."/".$attachment->name."','600','500')\" title=\"".$lang['common_open']." ".$attachment->name." ".$lang['common_inANewWindow']."\">".$attachment->name."</a><br>\n";
        next($taskInst->attachments);
        }

        It works on the local computer but not when other computers try to download it. Please help

        Please and Thank You.

          Kudose

          i'm sorry but your codes does not work. all it do is open a newwindows.

          Thank You

            Originally posted by Paingiver
            It works on the local computer but not when other computers try to download it.

            Then it sounds more like a firewall/router problem then a coding mistake....

              I only have a D-link switch,... no firewall

              Thank You

                just fyi, most switches these days have firmware firewalls built in...

                  ahh... a small US$ 50 switch with only 5 port ... i don't think there is a firewall in it.... how do i set/ see if there a firewall in the switch?

                  Please and Thank You

                    EDIT

                    <? echo "<a href='file.exe'>File To Download</a>"; ?>

                    Does work. Nuff said. /EDIT

                    Um, for one you could check your IP. If it is 192.168.XXX.XXX then youhave a router. Another way is to go to the manufactuer's website and see.

                    That script I wrote for you above should work, files automatically ask you to save or open them from the browser. I tested it on my server.

                    Here is the exact script I used.

                    HTML page

                    <html>
                    <body>
                    <div align="center"><a href="download.php?file=kazaa_lite_kpp_243_english.exe" target="_blank">Test Download File (KaZaA Lite) 
                      </a></div>
                    </body>
                    </html>
                    

                    PHP Page (download.php)

                    <?
                    $file = $HTTP_GET_VARS['file'];
                    header("Location: $file");
                    ?>
                    

                    You can alter this script to query your DB to get file names and all that jazz, but thats the answer to your original question.

                    To test it out go to

                    http://www.blvdcars.com/testfile.php

                    It will DL KaZaA Lite

                    It will only be up for tonight and maybe tomorrow, then I am deleteing it.

                      Kudose,
                      Your a hero! I've always want to know how websites did that,
                      a clever way to mask the file location, thanks again, much appreciated!

                        To trully mask the location of the file you could get the file ref (or whatever) from the url, copy the file to a unique temp file and then delete it at a later date.
                        Not sure how you would check to see if they'd finnished downloading though.
                        Bubble

                          is there another method of opening a file without redirecting the whole page?
                          what i mean is like you see on these pages:
                          If your download does not start automatically in the next x seconds then click here

                            I have a D-Link DES-1005D. I have not try to set the firewall. The things is that i can upload the file but not download it. what is the localtion format of $file? is it C:\download files\ or C:/download files?

                            Please and Thank You

                              i check the spec of the DES-1005D. I is an Unmanaged Stand-alone Dual Speed Switch with NO VLAN security. So there shouldn't be any firewall. I think it is the format the $file is located. I have put the file in the C:/temp when uploading.

                              Please and Thank You

                                Ohh sorry, the DES-1005D is also know as DSS-5+

                                Thank You

                                  Write a Reply...