設為首頁收藏本站

個人Points:5262   Rank: 9Rank: 9Rank: 9  管理員

文章日期:2011-11-22 11:58:39


防盗链需要,很多文件我们是不公开给客户看到真实的url的,用php的get参数带一个参数过去由php处理。

  1. ' D0 E0 {2 o- O$ D5 h( a! q' x
  2. $fileURL=;   
    " e1 W" N- Q( y9 o, |

  3. + k$ q" w6 a6 t  U. _9 n6 z8 H
  4. $filename=;   2 ~2 e2 s; B0 m
  5. ; V3 F+ F3 |  k4 p
  6. $file = @ fopen($fileURL,"r");   
    ' h" ?6 `/ [0 ]0 `" q+ _
  7. if (!$file) {   
      E3 _$ s6 V$ w" N! H5 V/ e
  8.     echo "文件找不到";   3 R6 o0 i5 r- q( R. \- M  x
  9. } else {   
    ) f/ b9 p$ `9 E( w' d( d$ Z, P4 O
  10.     Header("Content-type: application/octet-stream");   5 n  v4 {. H; l$ |0 b. j2 T
  11.     Header("Content-Disposition: attachment; filename=" . $filename);   
    / {6 ?3 m& g, p) s/ w- Q! Z3 K" Y
  12.     while (!feof ($file)) {   " x" v2 {. C6 A/ ]7 }: o
  13.         echo fread($file,50000);   
    4 D; B+ x, y7 V) g- j& f0 U6 N: q
  14.     }   ; x6 k( d5 F  m5 Y6 C
  15.     fclose (file);   
    . U* {' d. e: M+ a5 T
  16. }  
    - p/ D. Y4 V4 Y% ^9 B. H1 }* I' o
Copy
M2 討論區 © All Rights Reserved.

M2 討論區| (Language : 中文|English) Powered by Discuz! X2.5

GMT+8, 2024-6-2 22:09 , Processed in 0.087312 second(s), 24 queries , Gzip On.

Top