>  기사  >  백엔드 개발  >  PHP에서 다운로드 주소를 숨기는 방법

PHP에서 다운로드 주소를 숨기는 방법

coldplay.xixi
coldplay.xixi원래의
2020-10-05 14:14:122810검색

PHP에서 다운로드 주소를 숨기는 방법: PHP에서 헤더 메소드를 사용하세요. 코드는 [header("Cache-Control: must-revalidate, post-check=0, pre-check=0");]입니다.

PHP에서 다운로드 주소를 숨기는 방법

php 다운로드 주소 숨기기 방법:

php 실제 파일 다운로드 주소 숨기기 방법은 php

구현 방법 1:

function download_document($filename,$path="",$mimetype="application/octet-stream")
{
 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
 header("Content-Disposition: attachment; filename = $filename");
 header("Content-Length: " . filesize($pathto . $filename));
 header("Content-Type: $mimetype");
 echo file_get_contents($pathto . $filename);
}

구현 방법 2:

<?php
$file = "1.txt";// 文件的真实地址(支持url,不过不建议用url)
if (file_exists($file)) {
  header(&#39;Content-Description: File Transfer&#39;);
  header(&#39;Content-Type: application/octet-stream&#39;);
  header(&#39;Content-Disposition: attachment; filename=&#39;.basename($file));
  header(&#39;Content-Transfer-Encoding: binary&#39;);
  header(&#39;Expires: 0&#39;);
  header(&#39;Cache-Control: must-revalidate, post-check=0, pre-check=0&#39;);
  header(&#39;Pragma: public&#39;);
  header(&#39;Content-Length: &#39; . filesize($file));
  ob_clean();
  flush();
  readfile($file);
  exit;
}
?>

프로그래밍 학습에 대해 더 알고 싶다면 php training 칼럼을 주목해주세요!

위 내용은 PHP에서 다운로드 주소를 숨기는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.