HTTP 헤더를 생성하여 클라이언트에 데이터를 강제로 다운로드합니다. 이는 파일 다운로드를 구현할 때 유용합니다.
우선 @yangweijie의 작업 덕분에 php_fileinfo.dll 확장자를 열 필요가 없는 메서드가 파생되었습니다.
방법 1: 확장 프로그램 활성화//$file 文件路径<br>
public function download_file($file){<br>
if(is_file($file)){<br>
$length = filesize($file);<br>
$type = mime_content_type($file);<br>
$showname = ltrim(strrchr($file,'/'),'/');<br>
header("Content-Description: File Transfer");<br>
header('Content-type: ' . $type);<br>
header('Content-Length:' . $length);<br>
if (preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])) { //for IE<br>
header('Content-Disposition: attachment; filename="' . rawurlencode($showname) . '"');<br>
} else {<br>
header('Content-Disposition: attachment; filename="' . $showname . '"');<br>
}<br>
readfile($file);<br>
} else {<br>
$this->error('源文件不存在!');<br>
}<br>
}
//$file 파일 경로
공개 함수 download_file($file){<br>
If(is_file($file)){<br>
$length = 파일 크기($file);<br>
$type = mime_content_type($file);<br>
$showname = ltrim(strrchr($file,'/'),'/');<br>
header("콘텐츠 설명: 파일 전송");<br>
header('콘텐츠 유형: ' . $type);<br>
header('콘텐츠 길이:' . $length);<br>
If (preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])) { //IE의 경우<br>
header('Content-Disposition: attachment; filename="' . rawurlencode($showname) . '"');<br>
그 외 {<br>
header('콘텐츠 처리: attachment; filename="' . $showname . '"');<br>
}<br>
파일 읽기($file);<br>
} else {<br>
$this->error('소스 파일이 존재하지 않습니다!');<br>
}<br>
} }
방법 2, php_fileinfo.dll이 켜져 있지 않으면 누가 우리를 서버 권한 없이 프로그래머로 만들고 다른 사람들의 업신여김을 받을 수 없게 됩니까? 아마도 당신은 이해할 것입니다.
공개 함수 force_download($filename)
{
If ($filename == ''){
>
}
If (FALSE === strpos($filename, '.')){
>
}
$x = 폭발('.', $filename);
$extension = end($x);
$mimes =$this->getMimes();
//찾을 수 없는 경우 기본 MIME을 설정하세요
if ( !isset($mimes[$extension])){
$mime = 'application/octet-stream';
}그 외{
$mime = (is_array($mimes[$extension])) ? $mimes[$extension][0] : $mimes[$extension];
}
// 서버 헤더 생성
If (strpos($_SERVER['HTTP_USER_AGENT'], "MSIE") !== FALSE)
{
header('콘텐츠 유형: "'.$mime.'"');
header('Content-Disposition: attachment; filename="'.$filename.'"');
header('만료일: 0'); header('Cache-Control: 반드시 재검증, 사후 확인=0, 사전 확인=0');
header("콘텐츠 전송-인코딩: 바이너리");
header('Pragma: public');
header("콘텐츠 길이: ".filesize($filename));
}
그 외
{
header('Content-Type: "'.$mime.'"');
header('Content-Disposition: attachment; filename="'.$filename.'"');
header("콘텐츠 전송-인코딩: 바이너리");
header('만료: 0');
header('Pragma: no-cache');
header("콘텐츠 길이: ".filesize($filename));
}
파일 읽기($filename);
}
비공개 함수 getMimes(){
return $mimes = array( 'hqx' => 'application/mac-binhex40',
'cpt' => 'application/mac-compactpro',
'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel'),
'빈' => '애플리케이션/맥바이너리',
'DM' => '응용 프로그램/옥텟 스트림',
'라하' => '응용 프로그램/옥텟 스트림',
'lzh' => '애플리케이션/옥텟 스트림',
'exe' => array('application/octet-stream', 'application/x-msdownload'),
'수업' => '응용 프로그램/옥텟 스트림',
'psd' => 'application/x-photoshop',
'그래서' => '응용 프로그램/옥텟 스트림',
'바다' => '응용 프로그램/옥텟 스트림',
'dll' => '애플리케이션/옥텟 스트림',
'오다' => '어플리케이션/오다',
'pdf' => array('application/pdf', 'application/x-download'),
'아이' => '신청서/포스트스크립트',
'eps' => '신청서/포스트스크립트',
'ps' => '신청서/포스트스크립트',
'smi' => '신청/smil',
'미소' => '신청/smil',
'미프' => 'application/vnd.mif',
'xls' => array('application/excel', 'application/vnd.ms-excel', 'application/msexcel'),
'ppt' => array('application/powerpoint', 'application/vnd.ms-powerpoint'),
'wbxml' => '응용프로그램/wbxml',
'wmlc' => '응용프로그램/wmlc',
'dcr' => 'application/x-director',
'디렉터리' => 'application/x-director',
'dxr' => 'application/x-director',
'dvi' => '응용프로그램/x-dvi',
'gtar' => 'application/x-gtar',
'gz' => 'application/x-gzip',
'php' => 'application/x-httpd-php',
'php4' => 'application/x-httpd-php',
'php3' => 'application/x-httpd-php',
'phtml' => 'application/x-httpd-php',
'phps' => 'application/x-httpd-php-source',
'js' => 'application/x-javascript',
'swf' => 'application/x-shockwave-flash',
'앉아' => 'application/x-stuffit',
'타르' => 'application/x-tar',
'tgz' => array('application/x-tar', 'application/x-gzip-compressed'),
'xhtml' => 'application/xhtml+xml',
'xht' => 'application/xhtml+xml',
'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed'),
'중간' => '오디오/미디',
'미디' => '오디오/미디',
'mpga' => '오디오/mpeg',
'mp2' => '오디오/mpeg',
'mp3' => array('오디오/mpeg', '오디오/mpg', '오디오/mpeg3', '오디오/mp3'),
'aif' => '오디오/x-aiff',
'aiff' => '오디오/x-aiff',
'aifc' => '오디오/x-aiff',
'램' => '오디오/x-pn-realaudio',
'rm' => '오디오/x-pn-realaudio',
'rpm' => '오디오/x-pn-realaudio-플러그인',
'라' => '오디오/x-realaudio',
'rv' => 'video/vnd.rn-realvideo',
'wav' => array('audio/x-wav', 'audio/wave', 'audio/wav'),
'bmp' => array('이미지/bmp', '이미지/x-windows-bmp'),
'gif' => '이미지/gif',
'jpeg' => array('image/jpeg', 'image/pjpeg'),
'jpg' => array('image/jpeg', 'image/pjpeg'),
'jpe' => array('image/jpeg', 'image/pjpeg'),
'png' => array('이미지/png', '이미지/x-png'),
'티파니' => '이미지/tiff',
'티프' => '이미지/tiff',
'css' => '텍스트/CSS',
'html' => '텍스트/html',
'htm' => '텍스트/html',
'shtml' => '텍스트/html',
'txt' => '텍스트/일반',
'텍스트' => '텍스트/일반',
'로그' => array('text/plain', 'text/x-log'),
'rtx' => '텍스트/서식 있는 텍스트',
'rtf' => '텍스트/rtf',
'xml' => '텍스트/xml',
'xsl' => '텍스트/xml',
'mpeg' => '동영상/mpeg',
'mpg' => '동영상/mpeg',
'mpe' => '동영상/mpeg',
'qt' => '동영상/퀵타임',
'mov' => '동영상/퀵타임',
'avi' => '동영상/x-ms동영상',
'영화' => '동영상/x-sgi-movie',
'문서' => '응용프로그램/msword',
'docx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip'),
'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip'),
'단어' => array('application/msword', 'application/octet-stream'),
'xl' => '응용프로그램/엑셀',
'eml' => '메시지/rfc822',
'json' => array('application/json', 'text/json')
);이것을 보면 접미사가 파일 형식을 일치시키는 데 사용된다는 것을 모두가 이해하게 될 것입니다. mime_content_type의 기능을 구현합니다.
【광고】
쇼핑몰, 사무실, 기업 홈페이지, 유통 및 기타 시스템의 개발 및 2차 개발을 담당하고 있습니다. 상담을 환영합니다.

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

mPDF
mPDF는 UTF-8로 인코딩된 HTML에서 PDF 파일을 생성할 수 있는 PHP 라이브러리입니다. 원저자인 Ian Back은 자신의 웹 사이트에서 "즉시" PDF 파일을 출력하고 다양한 언어를 처리하기 위해 mPDF를 작성했습니다. HTML2FPDF와 같은 원본 스크립트보다 유니코드 글꼴을 사용할 때 속도가 느리고 더 큰 파일을 생성하지만 CSS 스타일 등을 지원하고 많은 개선 사항이 있습니다. RTL(아랍어, 히브리어), CJK(중국어, 일본어, 한국어)를 포함한 거의 모든 언어를 지원합니다. 중첩된 블록 수준 요소(예: P, DIV)를 지원합니다.

Eclipse용 SAP NetWeaver 서버 어댑터
Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.

WebStorm Mac 버전
유용한 JavaScript 개발 도구

MinGW - Windows용 미니멀리스트 GNU
이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.

VSCode Windows 64비트 다운로드
Microsoft에서 출시한 강력한 무료 IDE 편집기
