php实现将远程文件下载保存到服务器指定文件夹

yibin 2015-02-09 建站源码 760

直接上代码啦..

  1.       
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">         
  3. <html xmlns="http://www.w3.org/1999/xhtml" lang="zh-cn">         
  4. <head>         
  5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />         
  6. <meta http-equiv="Content-Language" content="UTF-8" />         
  7. </head>         
  8. <form method="post">         
  9. <input name="url" size="20" />         
  10. <input name="submit" type="submit" />         
  11. <!-- <input type="hidden" name="MAX_FILE_SIZE" value="2097152" />-->         
  12. </form>         
  13. <?php         
  14. set_time_limit (24 * 60 * 60);         
  15. if (!isset($_POST['submit'])) die();         
  16. $destination_folder = './downfolde/';   // 文件夹保存下载文件。必须以斜杠结尾        
  17. $url = $_POST['url'];         
  18. $newfname = $destination_folder . basename($url);         
  19. $file = fopen ($url"rb");         
  20. if ($file) {         
  21. $newf = fopen ($newfname"wb");         
  22. if ($newf)         
  23. while(!feof($file)) {         
  24. fwrite($newffread($file, 1024 * 8 ), 1024 * 8 );         
  25. }         
  26. }         
  27. if ($file) {         
  28. fclose($file);         
  29. }         
  30. if ($newf) {         
  31. fclose($newf);         
  32. }         
  33. ?>    

 

扫码添加微信

13013082126 扫描微信 建站咨询 优化咨询