Problem with save as at Safari for Windows

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • h3lp
    New Member
    • May 2007
    • 15

    Problem with save as at Safari for Windows

    Hello, i have a PHP script that will pop up a save as dialog box.
    This script works well at Firefox and IE7, but when i test it with Safari for Windows.
    It will download the PHP script itself and not the file that i want to give to user.
    Can someone help me, pls? Thanks in advance....
    [code=php]
    header("Content-disposition: attachment; filename=".$fil eName);
    header("Content-type: application/octet-stream");
    header("Pragma: no-cache");
    header("Expires : 0");

    $fp = fopen("$fileLoc ","r");
    $str = fread($fp, filesize($fileL oc));
    echo $str;
    fclose($fp);
    [/code]
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, h3lp.

    Try this:[code=php]
    header("Content-type: application/force-download");
    [/code]

    Comment

    • h3lp
      New Member
      • May 2007
      • 15

      #3
      Hi pbmods,
      I've tried ur code, but it still can't work.
      Safari still downloads the PHP script :(

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Heya, h3lp.

        Have a look at the comments on this page.

        (p.s., you can use readfile() to output the entire file in one step)

        Comment

        • h3lp
          New Member
          • May 2007
          • 15

          #5
          Sorry for the late reply, been busy for the last few days.
          Wow, pbmods. That one is working ;)
          Thanks a lot, really appreciate your help.
          Thx, thx, thx :D

          Comment

          • h3lp
            New Member
            • May 2007
            • 15

            #6
            Rrr, sorry pbmods.
            One more thing, if i want to download a jpg image. Safari will automatically open the image, instead of pop up a save dialog box.
            While Firefox & IE will ask user to download the jpg file.
            Can you help me again, pls? Thx

            Comment

            • pbmods
              Recognized Expert Expert
              • Apr 2007
              • 5821

              #7
              Heya, H3lp.

              Force-downloading an image file should use the same syntax as force-downloading any other file. If the browser insists on displaying the image, this might be a feature of the browser. Perhaps try zipping the file first.

              Incidentally, you can use fread() to output the file directly without having to worry about fopen() and fclose().

              Comment

              • nimeb
                New Member
                • Nov 2007
                • 1

                #8
                Hi,
                Having the same problem with vb.net2003 also...
                It saves the aspx page, instead of the excel i'm generating..
                Can some one help?

                Thanx

                Comment

                Working...