How to implement forced downloading of files or images in php

墨辰丷
Release: 2023-03-28 11:52:02
Original
1326 people have browsed it

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;
  }
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!