I need some sample scripts for downloading a exe file from server.
this one doesn't work!
header("Location: subpath/some.exe");

Thanks for any help!

    See the [man]header[/man] page for an example of the sort of headers that are required for your task. The example is for a PDF document with a MIME type of application/pdf; you'll be wanting to use application/octet-stream instead. There's some relevant discussion in the user notes, too, about bugs in various browsers.

      After reading the php.net's header manul, I wrote the scripts named
      download_page.php, it worked. That is, when a visitor clicked the link to the download_page.php, the file-save dialog was shown, and the file "MyProgram.exe"
      was downloaded.

      Below scripts is named as "download_page.php"

      <?
      $size=filesize("MyProgram.exe");
      header("Content-Type: application/exe");
      header("Content-Disposition: attachment; filename=MyProgram.exe");
      header("Content-Length: $size");
      header("Cache-control: private");

      $filename="MyProgram.exe";
      $fp =fopen($filename, 'r');
      fpassthru($fp);

      header("Location: MyProgram.exe");

      ?>

      I have 2 questions.
      1. the for-download file name shown on the prompted file-save dialog
      is "download_page.php", not "MyProgram.exe",
      How can resolve this error?

      1. header("Location: MyProgram.exe");
        Is this line really needed in the download_page.php?

      Thanks for any help!

        (1) This would be a browser bug; IE is guilty of it in various forms up until IE5.5 SP2, for example. TBH, I haven't got a workaround handy.

        (2) No; since you're no longer trying to redirect the browser to another location (since the executable it's downloading is now coming from this page). In fact, it would probably cause the downloaded file to be corrupted, because it would end up with a PHP Warning about "headers already sent" being attached to the end of the file.

          Hello, the scripts began to work correctly after I commented on the three lines in the file.

          <?
          $size=filesize("MyProgram.exe");
          header("Content-Type: application/exe");
          header("Content-Disposition: attachment; filename=MyProgram.exe");
          header("Content-Length: $size");
          header("Cache-control: private");

          //$filename="MyProgram.exe";
          //$fp =fopen($filename, 'r');
          //fpassthru($fp);

          header("Location: MyProgram.exe");

          ?>

            Write a Reply...