开发者

Download file from site PHP

I would to know the command in a PHP script开发者_高级运维 to get in output and save a file from my site. Thanks


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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜