設為首頁收藏本站

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

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


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

  1. ! k5 m4 V5 L% A4 s
  2. $fileURL=;   
    " Q. Y) {& r- m. E$ u
  3. ( W1 _. z+ S3 x5 ?2 \3 d3 V5 ]
  4. $filename=;   
    ! h2 o( |& ^% Z

  5. - P4 i. C9 C& C  z! u6 j: g& A) @
  6. $file = @ fopen($fileURL,"r");   
    1 f' C/ w3 F4 o3 @2 K
  7. if (!$file) {   + c- K, H# w* O& D+ s
  8.     echo "文件找不到";   
    8 p+ a7 k& r' R; {! p; h. V5 P5 E
  9. } else {   2 j+ i6 O8 L* B/ c3 x; D: ~
  10.     Header("Content-type: application/octet-stream");   ! J4 H/ d' o/ }, m: l+ }
  11.     Header("Content-Disposition: attachment; filename=" . $filename);   
    # ~; A/ t( J# A+ e- d" E6 O* x
  12.     while (!feof ($file)) {   # P5 J7 S3 Q) t  j& J
  13.         echo fread($file,50000);   
    1 g# P9 }& [( K7 a( `5 k, A
  14.     }   
    4 n2 _; P& S1 Z  T+ j
  15.     fclose (file);   + j! \  T* S0 z
  16. }  4 n9 Z$ d8 |7 K( b1 H5 t
Copy
M2 討論區 © All Rights Reserved.

M2 討論區 Powered by Discuz! X2.5

GMT+8, 2024-6-10 21:26 , Processed in 0.075229 second(s), 25 queries , Gzip On.

Top