Haloww everyone !!
I wanted to know the coding for downloading a file with php..
I already tried and the problem is that after i click the links it always automaticly open..like if i wanted to download a microsoft word file and it always open the microsoft word program and open the file automaticly..
this is my code :

<?
echo "<a href=files/$record[2]?id=$record[0]>Download file</a>";
?>

    What's the file type ... plain text or html or ... ?

      The file type is .doc, .xls, .jpg, & .gif... :-)

        Hmmm, I see your problem ... the browser is likely to be able to display all of these by default.

        Had a quick look at the 'Content-Disposition' section of the header() function and it seems do-able but with a couple of proviso's.

        Haven't had to do this myself, so can't guarantee it'll work.

          I already tried it but when i click the download links it's downloading the different file (download.html) where it should be filename.doc :-(

          <?
          include('search.conf.php');
          $query=mysql_query("SELECT * FROM tbl_keyword " ,$conn);

          header("Content-Disposition: attachment;filename=$namafile_name");
          ?>

            Could it be the Microsoft IE 5.5 bug?

              hehehe maybe ?!?! :-)

              From function header php manual :
              Note: There is a bug in Microsoft Internet Explorer 4.01 that prevents this from working. There is no workaround. There is also a bug in Microsoft Internet Explorer 5.5 that interferes with this, which can be resolved by upgrading to Service Pack 2 or later.

              But right know i'm using IE 6 and still got the problems..or maybe my coding is still worng :-(

                It's probably not your coding as it's pretty straightforward and you are getting the download box.

                The only problem is that the name on the 'download box' is the name of the PHP file that produces it, not the particular file that the script is programmed to download.

                I do know that the differences between 5.5 and 6 are minimal, so the bug might still apply.

                  Yup...maybe it's still had the bug for IE 6
                  but when i tried to download with another extension like .zip /.exe i get the download box just like i wanted... :-)
                  but thanks anyway for your help its very helpfull...

                  Best Regards..

                    Write a Reply...