設為首頁收藏本站

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

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


防盗链需要,很多文件我们是不公开给客户看到真实的url的,用php的get参数带一个参数过去由php处理。
  1. $ s. x$ l7 x: N
  2. $fileURL=;   ( Z- O8 _7 q' a/ ^
  3. ; y+ Z; b% V2 D1 V) T
  4. $filename=;   
    1 V- Q. l. v$ Z/ G8 @) k. F2 S
  5. ' }5 f3 ~! @; t, z8 a4 V+ z! c* `
  6. $file = @ fopen($fileURL,"r");   
    , x2 s/ O: d$ R; k% I
  7. if (!$file) {   1 }  _) ^; Y( |$ P9 ]' Q
  8.     echo "文件找不到";   7 h6 S+ n. ?6 L3 p
  9. } else {   
    7 L. R' w$ i+ W2 f( c6 Y; {0 ^
  10.     Header("Content-type: application/octet-stream");   
    - m# \3 z! }- l& c
  11.     Header("Content-Disposition: attachment; filename=" . $filename);   4 b. f1 Q# G  }6 _3 Q" c1 l" W6 Y, D
  12.     while (!feof ($file)) {   & ], U$ ]9 ~3 p5 v' C! D& o8 W
  13.         echo fread($file,50000);   
    - R/ ^$ ~6 w$ j5 r$ N( ^
  14.     }   9 \$ `* r* J- h5 [' \4 {/ `
  15.     fclose (file);   
    1 C+ c7 M) @0 C* Y4 D' R) A
  16. }  
    % S8 [: C5 Y* |" ]5 N
Copy
M2 討論區 © All Rights Reserved.

M2 討論區 Powered by Discuz! X2.5

GMT+8, 2024-5-16 04:55 , Processed in 0.097150 second(s), 24 queries , Gzip On.

Top