0

I would to know the command in a PHP script to get in output and save a file from my site. Thanks

Guido
  • 6,853
  • 3
  • 16
  • 9
  • 1
    Are you saying that you would like to know how to initiate a file download for the user browsing your site? – Alistair Evans Apr 16 '10 at 09:05
  • 3
    Sorry, it's not very clear what you want. Could you try to explain it in different words or by example? – deceze Apr 16 '10 at 09:05
  • *(reference)* http://de2.php.net/manual/en/function.header.php (see Example #1 Download dialog) – Gordon Apr 16 '10 at 09:08

3 Answers3

1

See here for a good description of how to force the output of a php script to be a download.

The basics of it are:

// Set headers
 header("Cache-Control: public");
 header("Content-Description: File Download");
 header("Content-Disposition: attachment; filename=" + $filename);
 header("Content-Type: application/zip"); // or whatever the mime-type is
                                          // for the file you want to download
 header("Content-Transfer-Encoding: binary");

 // Read the file from disk
 readfile($full_path_to_file);

As an addition (provided by Gordon's comment), see the 1st example on the php documentation here

Alistair Evans
  • 36,057
  • 7
  • 42
  • 54
0

At the End of the files or used in clicking files, you can add this

        $filesh = "check.xls";

        header("Pragma: public");
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Content-Type: application/force-download");
        header("Content-Disposition: attachment; filename=".basename($filesh));
        header("Content-Description: File Transfer");
        readfile($filesh);

if you got any header using problem means, top of the file you can add ob_start(); function

Karthik
  • 3,221
  • 5
  • 28
  • 38
0

If you mean getting output, contents from other site or location, this what you need file_get_contents

deceze
  • 510,633
  • 85
  • 743
  • 889
jerjer
  • 8,694
  • 30
  • 36