首页 > PHP资讯 > PHP培训技术 > php如何简单实现文件或图片强制下载的方法

php如何简单实现文件或图片强制下载的方法

PHP培训技术

  php如何简单实现文件或图片强制下载的方法

//下载
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;
  }
}

文章来自于南京欣才PHP培训机构

本文由欣才IT学院整理发布,未经许可,禁止转载。