开发者

How to give a download option [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. 开发者_如何学Python Closed 10 years ago.

I am making a site on which I'll give users the option to download software.

I want to know what to do for that.

For example:

To download xyz software click here

and if the user clicks on it, the download starts.


<p>You can download <a href="/url/to/the/file/to/download">the thing that you want</a>


You can use this function:

function download($path, $filename) {

  header('Content-Type: application/force-download');
  header('Content-Disposition: attachment;filename="'. $filename . '"');
  $fp=fopen($path . "/". $filename, 'r');
  fpassthru($fp);
  fclose($fp);

}

Next, you have to set values for $path & $filename & call the above function like this:

$path = $_SERVER['DOCUMENT_ROOT']."/your_download_directory";
$filename = xyz_software.zip;

download($path, $filename);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜