設為首頁收藏本站

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

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


防盗链需要,很多文件我们是不公开给客户看到真实的url的,用php的get参数带一个参数过去由php处理。
  1. ) W. m0 N5 l! t: ]7 F
  2. $fileURL=;   
    9 K- U8 o! a6 d( T  }
  3. + a0 ~; h6 e! @0 m- c) O
  4. $filename=;   
    , M; \! ?5 `5 x7 d# {3 V) B
  5. 8 l/ c& b$ S2 y2 K' r
  6. $file = @ fopen($fileURL,"r");   " r" A$ T; R9 ]+ P$ \
  7. if (!$file) {   
    1 w: |- |+ U+ A8 Q  E+ Y0 A# `
  8.     echo "文件找不到";   
    0 F9 X1 B* r2 a9 w, `; {2 _- Q
  9. } else {   
    9 J9 J: q8 K' Q0 r% {& V) v
  10.     Header("Content-type: application/octet-stream");   , ?1 x( _% Z* v. }, R
  11.     Header("Content-Disposition: attachment; filename=" . $filename);   - l7 R7 q0 }1 [0 l
  12.     while (!feof ($file)) {   ' _3 \. d/ H! E
  13.         echo fread($file,50000);   
    # I' h9 H2 W- d8 U1 z, H
  14.     }   
    3 Q- y0 n2 Y8 S7 F8 M1 W6 G6 H
  15.     fclose (file);   : F9 j3 u, w' q/ ^! o1 B
  16. }  
    1 l9 d- A+ h; {2 T
Copy
M2 討論區 © All Rights Reserved.

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

GMT+8, 2024-6-15 10:58 , Processed in 0.081832 second(s), 24 queries , Gzip On.

Top