Discuz教程网

[其他教程] Discuz X2.5利用计划任务每日下载Alexa的数据(炎藤)

[复制链接]
authicon dly 发表于 2012-12-2 23:38:49 | 显示全部楼层 |阅读模式
首先放置这段代码到 /source/include/cron/ 目录下面,命名为 alexaDownload.php


  1. <?php
  2. # author: 炎藤
  3. # website: cnBayarea.com

  4. $thisYear = date("Y");
  5. $dateToday = date("Ymd");
  6. $url = "http://s3.amazonaws.com/alexa-static/top-1m.csv.zip";
  7. $path = "./alexa/".$thisYear."/".$dateToday.".zip";
  8. $zip = new ZipArchive;
  9. $newName = $dateToday.".txt";
  10. $zipDir = "./alexa/".$thisYear."/";

  11. // create folder
  12. if(!is_dir($thisYear)){
  13. if(!mkdir($thisYear, 0777)) {
  14. die('Failed to create folders...');
  15. };
  16. }
  17. // download
  18. if(!is_file($path)){
  19. $ch = curl_init($url);
  20. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  21. $data = curl_exec($ch);
  22. curl_close($ch);
  23. file_put_contents($path, $data);
  24. }
  25. // unzip
  26. // unzip 1/2 - rename file
  27. if ($zip->open($path)) {
  28. $zip->renameName('top-1m.csv', $newName);
  29. $zip->close();
  30. } else {
  31. echo 'fail to open zip file';
  32. }
  33. // unzip 2/2 - unzip file
  34. if ($zip->open($path)) {
  35. $zip->extractTo($zipDir);
  36. } else {
  37. echo 'fail to unzip file';
  38. }
  39. ?>
复制代码

这段代码会把文件下载到 /alexa/ 目录下,并按时间日期来排列
实例: http://cnbayarea.com/alexa/2012/1201.txt



上一篇:PHP自定义的Unicode编码转GBK,GBK转Unicode编码函数
下一篇:1314学习网签到记录贴-2012年12月3日
authicon 亘古つ守侯珊 发表于 2012-12-3 08:55:33 | 显示全部楼层
不错 但是有什么实用价值么?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2024-5-18 13:58

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表