防盗链需要,很多文件我们是不公开给客户看到真实的url的,用php的get参数带一个参数过去由php处理。- ) n; T( m8 |, c3 s. D
- $fileURL=; " S/ F. p5 o" E9 C) j
- & S: x! G; e7 k# S, ^1 f
- $filename=; * c& Z' V4 @6 }! ~
6 K2 M% [) b% t3 ?4 X- $file = @ fopen($fileURL,"r"); / D* R7 g; U* x5 ~/ C$ [
- if (!$file) {
) q; f: J, e' V9 f( o3 v - echo "文件找不到";
s9 p+ K$ m$ W/ O - } else { 0 x9 `! p* K5 x* [
- Header("Content-type: application/octet-stream");
/ u& h- i; {. t6 |$ Z; s3 E) N - Header("Content-Disposition: attachment; filename=" . $filename);
' J: } E4 U" i5 | - while (!feof ($file)) {
3 U2 P' ~$ Z! F- N: N - echo fread($file,50000); 2 e. d B- J% t: l
- } , P4 X0 h* G2 Q. d# s" t8 [* U0 \
- fclose (file);
j& P0 Y1 i- E; S4 ] - }
4 w3 J, y2 L' o! @1 T6 q% V! j g% Y
Copy |
|