Use header definition as file and ReadFile download _php tutorial

Source: Internet
Author: User
Tags dbx fdf pkcs12 pkcs7 readfile rfc822
Sometimes we in order to hide the real download address, we use the header definition as a file and then ReadFile download, but this will increase the burden on the server, generally not recommended to download a larger number of files

The code is as follows: = $lastModified) {header ("http/1.1 304 not Modified"); return true;} if (Isset ($_server[' http_if_unmodified_since ']) &am p;& strtotime ($_server[' http_if_unmodified_since ') < $lastModified) {header ("http/1.1 304 not Modified"); return true; } if (Isset ($_server[' Http_if_none_match ')) && $_server[' http_if_none_match '] = = $etag) {header ("http/1.1 304 Not Modified "); return true; if ($fancyName = = ") {$fancyName = basename ($fileName);} if ($contentType = =") {$contentType = ' application/octet- Stream '; } $fileSize = $fileStat [' Size ']; $contentLength = $fileSize; $isPartial = false; if (Isset ($_server[' Http_range ')) {if (Preg_match ('/^bytes= ' (d*)-(d*) $/', $_server[' Http_range '], $matches)) {$ startpos = $matches [1]; $endPos = $matches [2]; if ($startPos = = "&& $endPos = =") {return false;} if ($startPos = = ") {$startPos = $fileSize-$endPos; $e Ndpos = $fileSize-1; } else if ($endPos = = ") {$endPos = $fileSize-1;} $startPos = $startPos < 0? 0: $startPos; $endPos = $endPos > $fileSize-1? $fileSize-1: $endPos; $length = $endPos-$startPos + 1; if ($length < 0) {return false;} $contentLength = $length; $isPartial = true; }}//Send headers if ($isPartial) {header (' http/1.1 206 Partial Content '); header ("Content-range:bytes $startPos-$endP os/$fileSize "); } else {header ("http/1.1"), $startPos = 0; $endPos = $contentLength-1;} header (' Pragma:cache '); Header (' Cache-control:public, must-revalidate, max-age=0 '); Header (' accept-ranges:bytes '); Header (' Content-type: '. $contentType); Header (' Content-length: '. $contentLength); if ($forceDownload) {header (' content-disposition:attachment; Filename= '. Rawurlencode ($fancyName). ' "');//The Chinese character is automatically converted to the URL code header (' Content-disposition:attachment; Filename= "'. $fancyName. '"'); } Header ("Content-transfer-encoding:binary"); $bufferSize = 2048; if ($speedLimit! = 0) {$packetTime = Floor ($bufferSize * 1000000/$speedLimit);} $bytesSent = 0; $fp = fopen ($fiLename, "RB"); Fseek ($fp, $startPos); Fpassthru ($FP); while ($bytesSent < $contentLength &&!feof ($fp) && connection_status () = = 0) {if ($speedLimit! = 0) {List ($usec, $sec) = Explode ("", Microtime ()); $outputTimeStart = ((float) $usec + (float) $sec); } $readBufferSize = $contentLength-$bytesSent < $bufferSize? $contentLength-$bytesSent: $bufferSize; $buffer = Fread ($fp, $readBufferSize); Echo $buffer; Ob_flush (); Flush (); $bytesSent + = $readBufferSize; if ($speedLimit! = 0) {list ($usec, $sec) = Explode ("", Microtime ()); $outputTimeEnd = ((float) $usec + (float) $sec); $useTime = ((float) $outputTimeEnd-(float) $outputTimeStart) * 1000000; $sleepTime = Round ($packetTime-$useTime); if ($sleepTime > 0) {usleep ($sleepTime);}} } return true; The?> attached server responds to the type of HTTP ContentType Daquan: ". *" = "Application/octet-stream" ". 001" = "application/x-001" ". 301" = "application/ x-301 "". 323 "=" text/h323 "". 906 "=" application/x-906 "". 907 "=" drawing/907 "". A11 "=" Application/x-a11 "". ACP "=" AUDIO/X-MEI-AAC "". Ai "=" application/postscript "". AIF "=" Audio/aiff "". aifc "=" Audio/aiff "". Aiff "=" audio/ Aiff "". Anv "=" Application/x-anv "". Asa "=" Text/asa "". asf "=" video/x-ms-asf "". asp "=" text/asp "". asx "=" video/x-ms-asf ". Au" = "audio/basic" ". avi" = "Video/avi" ". Awf" = "Application/vnd.adobe.workflow" ". Biz" = "Text/xml" ". bmp" = " Application/x-bmp "". Bot "=" Application/x-bot "". c4t "=" application/x-c4t "". C90 "=" Application/x-c90 "". Cal "=" Application/x-cals "". Cat "=" Application/vnd.ms-pki.seccat "". CDF "=" APPLICATION/X-NETCDF "". Cdr "=" application/ X-cdr "". Cel "=" Application/x-cel "". cer "=" Application/x-x509-ca-cert "". Cg4 "=" Application/x-g4 "". CGM "=" APPLICATION/X-CGM "". cit "=" Application/x-cit "". Class "=" java/* "". CML "=" Text/xml "". cmp "=" application/x-cmp "". CMX " = "APPLICATION/X-CMX" ". Cot" = "Application/x-cot" ". CRL" = "application/pkix-crl" ". Crt" = "Application/x-x509-ca-cert" ". CSI" = "Application/x-csi" ". css" = "text/css" ". Cut" = "Application/x-cut" ". dbf" = "application/x-dbf" ". dbm" = " APPLICATION/X-DBM "". dbx "=" application/x-dbx "". DCD "=" Text/xml "". Dcx "=" Application/x-dcx "". Der "=" Application/x-x509-ca-cert "". DGN "=" APPLICATION/X-DGN "". Dib "=" Application/x-dib "". dll "=" Application/x-msdownload "". Doc "=" Application/msword "". Dot "=" Application/msword "". DRW "=" APPLICATION/X-DRW "". DTD "=" Text/xml "". DWF "=" MODEL/VND.DWF "". DWF "=" APPLICATION/X-DWF "". dwg "=" application/ X-dwg "". Dxb "=" APPLICATION/X-DXB "". DXF "=" application/x-dxf "". Edn "=" Application/vnd.adobe.edn "". EMF "=" Application/x-emf "". eml "=" message/rfc822 "". Ent "=" Text/xml "". Epi "=" Application/x-epi "". EPs "=" Application/x-ps "" . eps "=" Application/postscript "". etd "=" application/x-ebx "". exe "=" application/x-msdownload "". Fax "=" Image/fax "". FDF "=" Application/vnd.fdf "". Fif "=" Application/fractals "". Fo "=" text/xml "". frm "=" application/x-frm "". G4 "=" Application/x-g4 "". GBR "=" APPLICATION/X-GBR "". gcd "=" APPLICATION/X-GCD "". gif "=" image/gif "". Gl2 "=" application/ X-gl2 "". Gp4 "=" Application/x-gp4 "". Hgl "=" Application/x-hgl "". HMR "=" APPLICATION/X-HMR "". Hpg "=" APPLICATION/X-HPGL ". HPL" = "APPLICATION/X-HPL" ". hqx" = "APplication/mac-binhex40 "". Hrf "=" APPLICATION/X-HRF "". HTA "=" Application/hta "". HTC "=" text/x-component "". htm "=" Text/html "". html "=" text/html "". Htt "=" text/webviewhtml "". htx "=" text/html "". ICB "=" APPLICATION/X-ICB "". ico "=" Image/x-icon "". ico "=" Application/x-ico "". IFF "=" Application/x-iff "". Ig4 "=" Application/x-g4 "". IGs "=" application/ X-igs "". III "=" Application/x-iphone "". img "=" application/x-img "". Ins "=" Application/x-internet-signup "". ISP "=" Application/x-internet-signup "". IVF "=" VIDEO/X-IVF "". Java "=" java/* "". Jfif "=" Image/jpeg "". Jpe "=" Image/jpeg "". Jpe "=" Application/x-jpe "". jpeg "=" Image/jpeg "". jpg "=" image/jpeg "". jpg "=" application/x-jpg "". js "=" Application/x-javascript "". jsp "=" text/html "". La1 "=" Audio/x-liquid-file "". Lar "=" Application/x-laplayer-reg "". Latex "=" Application/x-latex "". LAVs "=" audio/ X-liquid-secure "". LBM "=" APPLICATION/X-LBM "". Lmsff "=" Audio/x-la-lms "". ls "=" application/x-javascript "". Ltr "=" Application/x-ltr "". m1v "=" Video/x-mpeg "". m2v "=" Video/x-mpeg "". m3u "=" Audio/mpegurl "". m4e "=" VIDEO/MPEG4 "". Mac "="Application/x-mac" ". Man" = "Application/x-troff-man" ". Math" = "Text/xml" ". mdb" = "application/msaccess" ". mdb" = " Application/x-mdb "". MFP "=" Application/x-shockwave-flash "". mht "=" message/rfc822 "". mhtml "=" message/rfc822 "". Mi "= "Application/x-mi" ". Mid" = "Audio/mid" ". Midi" = "Audio/mid" ". Mil" = "Application/x-mil" ". MML" = "Text/xml" ". MND" = " Audio/x-musicnet-download "". MNs "=" Audio/x-musicnet-stream "". Mocha "=" Application/x-javascript "". Movie "=" video/ X-sgi-movie "". Mp1 "=" Audio/mp1 "". Mp2 "=" AUDIO/MP2 "". mp2v "=" Video/mpeg "". mp3 "=" Audio/mp3 "". mp4 "=" VIDEO/MPEG4 "". MPA "=" Video/x-mpg "". MPD "=" Application/vnd.ms-project "". Mpe "=" Video/x-mpeg "". Mpeg "=" Video/mpg "". mpg "=" video/mpg ". MPGA" = "Audio/rn-mpeg" ". MPP" = "Application/vnd.ms-project" ". MPs" = "video/x-mpeg" ". MPT" = "application/ Vnd.ms-project "". MPV "=" Video/mpg "". Mpv2 "=" Video/mpeg "". MPW "=" Application/vnd.ms-project "". MPX "=" application/ Vnd.ms-project "". MTx "=" Text/xml "". MXP "=" APPLICATION/X-MMXP "". Net "=" Image/pnetvue "". NRF "=" APPLICATION/X-NRF "". NWS "=" message/rfc822 "". odc "=" text/X-ms-odc "". Out "=" Application/x-out "". P10 "=" Application/pkcs10 "". P12 "=" application/x-pkcs12 "". p7b "=" Application /x-pkcs7-certificates "". p7c "=" Application/pkcs7-mime "". p7m "=" Application/pkcs7-mime "". p7r "=" application/ X-pkcs7-certreqresp "". P7s "=" Application/pkcs7-signature "". Pc5 "=" APPLICATION/X-PC5 "". PCI "=" Application/x-pci "". PCL "=" APPLICATION/X-PCL "". pcx "=" application/x-pcx "". pdf "=" Application/pdf "". pdf "=" Application/pdf "". Pdx "=" Application/vnd.adobe.pdx "". pfx "=" application/x-pkcs12 "". PGL "=" APPLICATION/X-PGL "". Pic "=" Application/x-pic "". Pko "=" Application/vnd.ms-pki.pko "". pl "=" Application/x-perl "". PLG "=" text/html "". Pls "=" audio/scpls "". Plt "=" Application/x-plt "". png "=" image/png "". png "=" application/x-png "". Pot "=" application/vnd.ms-powerpoint "". PPA "=" Application/vnd.ms-powerpoint "". ppm "=" application/x-ppm "". pps "=" Application/vnd.ms-powerpoint "". ppt "=" Application/vnd.ms-powerpoint "". ppt "=" application/x-ppt "". PR "=" APPLICATION/X-PR "". PRF "=" application/pics-rules ". prn" = "application/x-prn" ". Prt" = "APplication/x-prt "". PS "=" Application/x-ps "". PS "=" Application/postscript "". Ptn "=" Application/x-ptn "". Pwz "=" Application/vnd.ms-powerpoint "". r3t "=" Text/vnd.rn-realtext3d "". Ra "=" Audio/vnd.rn-realaudio "". Ram "=" audio/ X-pn-realaudio "". Ras "=" Application/x-ras "". Rat "=" Application/rat-file "". RDF "=" Text/xml "". Rec "=" application/ Vnd.rn-recording "". Red "=" application/x-red "". RGB "=" Application/x-rgb "". RJs "=" Application/vnd.rn-realsystem-rjs ". Rjt" = "Application/vnd.rn-realsystem-rjt" ". RLC" = "APPLICATION/X-RLC" ". Rle" = "Application/x-rle" ". RM" = " Application/vnd.rn-realmedia "". Rmf "=" APPLICATION/VND.ADOBE.RMF "". Rmi "=" Audio/mid "". Rmj "=" application/ VND.RN-REALSYSTEM-RMJ "". RMM "=" Audio/x-pn-realaudio "". RMP "=" Application/vnd.rn-rn_music_package "". RMS "=" Application/vnd.rn-realmedia-secure "". rmvb "=" APPLICATION/VND.RN-REALMEDIA-VBR "". Rmx "=" application/ Vnd.rn-realsystem-rmx "". Rnx "=" Application/vnd.rn-realplayer "". RP "=" Image/vnd.rn-realpix "". RPM "=" audio/ X-pn-realaudio-plugin "". Rsml "=" APPLICATION/VND.RN-RSML "". RT "=" text/Vnd.rn-realtext ". rtf" = "Application/msword" ". rtf" = "Application/x-rtf" ". RV" = "Video/vnd.rn-realvideo" ". Sam" = " Application/x-sam "". Sat "=" Application/x-sat "". SDP "=" APPLICATION/SDP "". Sdw "=" Application/x-sdw "". Sit "=" Application/x-stuffit "". SLB "=" application/x-slb "". SLD "=" APPLICATION/X-SLD "". SLK "=" drawing/x-slk "". Smi "=" Application/smil "". Smil "=" Application/smil "". SMK "=" APPLICATION/X-SMK "". snd "=" Audio/basic "". Sol "=" Text/plain "". Sor "=" Text/plain "". SPC "=" application/x-pkcs7-certificates "". SPL "=" Application/futuresplash "". spp "=" Text/xml "". SSM "=" Application/streamingmedia "". SST "=" Application/vnd.ms-pki.certstore "". StL "=" Application/vnd.ms-pki.stl "" . stm "=" text/html "". Sty "=" Application/x-sty "". svg "=" text/xml "". swf "=" Application/x-shockwave-flash "". TDF "=" Application/x-tdf "". TG4 "=" APPLICATION/X-TG4 "". TGA "=" application/x-tga "". tif "=" Image/tiff "". tif "=" application/ X-tif "". Tiff "=" Image/tiff "". TLD "=" Text/xml "". Top "=" drawing/x-top "". Torrent "=" application/x-bittorrent "". TSD "=" Text/xml "". txt "=" Text/plain "". UIn "=" Application/x-icq "". Uls "=" Text/iuls "". vcf "=" Text/x-vcard "". Vda "=" Application/x-vda "". vdx "=" application/ Vnd.visio "". VML "=" Text/xml "". VPg "=" application/x-vpeg005 "". Vsd "=" Application/vnd.visio "". Vsd "=" application/ X-vsd "". vss "=" Application/vnd.visio "". vst "=" Application/vnd.visio "". vst "=" Application/x-vst "". Vsw "=" Application/vnd.visio "". Vsx "=" Application/vnd.visio "". vtx "=" Application/vnd.visio "". Vxml "=" Text/xml "". wav "=" Audio/wav "". Wax "=" audio/x-ms-wax "". Wb1 "=" application/x-wb1 "". Wb2 "=" application/x-wb2 "". Wb3 "=" application/x-wb3 ". Wbmp" = "Image/vnd.wap.wbmp" ". Wiz" = "Application/msword" ". Wk3" = "Application/x-wk3" ". Wk4" = "Application/x-wk4" ". Wkq "=" APPLICATION/X-WKQ "". Wks "=" Application/x-wks "". Wm "=" VIDEO/X-MS-WM "". wma "=" audio/x-ms-wma "". WMD "=" APPLICATION/X-MS-WMD "". Wmf "=" application/x-wmf "". WML "=" TEXT/VND.WAP.WML "". wmv "=" video/x-ms-wmv "". Wmx "=" video/ X-ms-wmx "". wmz "=" Application/x-ms-wmz "". Wp6 "=" Application/x-wp6 "". WPD "=" APPLICATION/X-WPD "". WPG "=" application/ X-WPG "". WPL "=" APPLICATION/VND.MS-WPL "". Wq1" = "application/x-wq1" ". Wr1" = "Application/x-wr1" ". Wri" = "Application/x-wri" ". Wrk" = "Application/x-wrk" ". ws" = "Application/x-ws" ". Ws2" = "Application/x-ws" ". WSC" = "Text/scriptlet" ". wsdl" = "Text/xml" ". wvx" = "video/x-ms-wvx" ". XDP "=" APPLICATION/VND.ADOBE.XDP "". XDR "=" Text/xml "". XfD "=" Application/vnd.adobe.xfd "". Xfdf "=" application/ Vnd.adobe.xfdf "". xhtml "=" text/html "". xls "=" application/vnd.ms-excel "". xls "=" Application/x-xls "". xlw "=" APPLICATION/X-XLW "". xml "=" Text/xml "". xPL "=" Audio/scpls "". Xq "=" Text/xml "". Xql "=" Text/xml "". XQuery "=" Text/xml "". xsd "=" text/xml "". xsl "=" Text/xml "". xslt "=" Text/xml "". Xwd "=" application/x-xwd "". X_b "=" Application/x-x_b "". x_t "=" application/x-x_t "

http://www.bkjia.com/PHPjc/730220.html www.bkjia.com true http://www.bkjia.com/PHPjc/730220.html techarticle sometimes we in order to hide the real download address, we use the header definition as a file and then ReadFile download, but this will increase the burden of the server, generally not recommended download volume comparison ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.