views:

72

answers:

3

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

+1  A: 

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

Kazar
A: 

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
A: 

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

jerjer