PHP将远程文件下载至本地服务器
<HTML lang=zh-cn xmlns="http://www.w3.org/1999/xhtml">
02 <HEAD>
03
04
05 <META http-equiv=Content-Language content=UTF-8>
06
07 <FORM method=post>
08 <INPUT name=url>
09 <INPUT type=submit value=提交查询内容 name=submit>
10 <!--
11 <input type="hidden" name="MAX_FILE_SIZE" value="2097152" />-->
12 </FORM>
13
14 <?php
15 set_time_limit (24 * 60 * 60);
16 if (!isset($_POST['submit'])) die();
17 $destination_folder = './downfold/'; // 文件夹保存下载文件,必须以斜杠结尾,此处没有判断是否存在文件夹,故需你自己建一个名为downfold的文件夹
18 $url = $_POST['url'];
19 $newfname = $destination_folder . basename($url);
20 $file = fopen ($url, "rb");
21 if ($file) {
22 $newf = fopen ($newfname, "wb");
23 if ($newf)
24 while(!feof($file)) {
25 fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 );
26 }
27 }
28 if ($file) {
29 fclose($file);
30 }
31 if ($newf) {
32 fclose($newf);
33 }
34 ?>
posted on 2012-02-01 10:59 kudosharry 阅读(686) 评论(0) 编辑 收藏 举报