Home  >  Article  >  Backend Development  >  How to implement forced downloading of files or images in php

How to implement forced downloading of files or images in php

墨辰丷
墨辰丷Original
2018-05-29 17:26:211348browse

This article mainly introduces the method of forced downloading of files or pictures in PHP, and implements simple reading and output related operation skills of files or pictures through custom functions. Friends in need can refer to the following

for details As follows:

//下载
function downregcaseAction() {
  $file="upload/regcase.jpg";
  if(isfile($file)) {
    header("Content-Type: application/force-download");
    header("Content-Disposition: attachment; filename=".basename(file));
    readfile(file);
    exit;
  } else {
    echo "文件不存在!";
    exit;
  }
}

The above is the entire content of this article, I hope it will be helpful to everyone's study.


Related recommendations: Examples of PDO transaction processing operations in

PHP

PHPHow to automatically load classes in

##PHPSimple method of parsing xml into an array

The above is the detailed content of How to implement forced downloading of files or images in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn