設為首頁收藏本站

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

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


防盗链需要,很多文件我们是不公开给客户看到真实的url的,用php的get参数带一个参数过去由php处理。
  1. ) n; T( m8 |, c3 s. D
  2. $fileURL=;   " S/ F. p5 o" E9 C) j
  3. & S: x! G; e7 k# S, ^1 f
  4. $filename=;   * c& Z' V4 @6 }! ~

  5. 6 K2 M% [) b% t3 ?4 X
  6. $file = @ fopen($fileURL,"r");   / D* R7 g; U* x5 ~/ C$ [
  7. if (!$file) {   
    ) q; f: J, e' V9 f( o3 v
  8.     echo "文件找不到";   
      s9 p+ K$ m$ W/ O
  9. } else {   0 x9 `! p* K5 x* [
  10.     Header("Content-type: application/octet-stream");   
    / u& h- i; {. t6 |$ Z; s3 E) N
  11.     Header("Content-Disposition: attachment; filename=" . $filename);   
    ' J: }  E4 U" i5 |
  12.     while (!feof ($file)) {   
    3 U2 P' ~$ Z! F- N: N
  13.         echo fread($file,50000);   2 e. d  B- J% t: l
  14.     }   , P4 X0 h* G2 Q. d# s" t8 [* U0 \
  15.     fclose (file);   
      j& P0 Y1 i- E; S4 ]
  16. }  
    4 w3 J, y2 L' o! @1 T6 q% V! j  g% Y
Copy
M2 討論區 © All Rights Reserved.

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

GMT+8, 2024-5-16 07:53 , Processed in 0.079125 second(s), 24 queries , Gzip On.

Top