設為首頁收藏本站

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

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


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

  1. , I7 d* h: A0 {! ?8 n
  2. $fileURL=;   
    . y5 k% t) l9 l4 N

  3. 8 S5 x+ Z* c; B; H: Q! o/ B" J# Y5 P! W
  4. $filename=;   
    7 N& x9 S1 o3 d* V

  5. # q- d- M6 H  v. O# t& y/ G$ \- b( L; d
  6. $file = @ fopen($fileURL,"r");   + c2 ]  c; N' V- t! H
  7. if (!$file) {   & J" G% o# G1 d6 b7 a. t) v
  8.     echo "文件找不到";   3 ?% V3 x# r, Q
  9. } else {   
    + D, Y: w4 R& Y! @" V
  10.     Header("Content-type: application/octet-stream");   : P3 F+ n  R6 r9 H* D5 X  i* v
  11.     Header("Content-Disposition: attachment; filename=" . $filename);   + J( t% s- a& H9 f0 X1 I
  12.     while (!feof ($file)) {   
    ) f) S* \# Z- S5 [
  13.         echo fread($file,50000);   " N* L  [) U! t2 a- k+ [$ ^
  14.     }   " t8 s: b* ]% q, o# I8 V/ e) M8 g. c
  15.     fclose (file);   
    6 k. X2 b/ w7 {
  16. }  3 g9 c" l. y3 o- g; x& ?4 n# ~9 [
Copy
M2 討論區 © All Rights Reserved.

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

GMT+8, 2024-5-16 03:40 , Processed in 0.094433 second(s), 24 queries , Gzip On.

Top