index.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. // error_reporting(0);
  3. $path=date('Ym');
  4. if (!file_exists($path)) {
  5. mkdir($path, 0777);
  6. }
  7. $last = strtotime("-1 month", time());
  8. $last_month = date("Ym", $last);//上个月
  9. if (file_exists($last_month)) {
  10. deleteDir($last_month);
  11. }
  12. $pathurl = $path.'/'.date('d').'.jpg';
  13. if (!is_file($pathurl)) {
  14. $str=file_get_contents('http://cn.bing.com/HPImageArchive.aspx?idx=0&n=1');
  15. if (preg_match("/<urlBase>(.+?)<\/urlBase>/ies", $str, $matches)) {
  16. $imgurl='http://cn.bing.com'.$matches[1].'_1920x1080.jpg';
  17. copy($imgurl, $pathurl);
  18. } else {
  19. copy('https://dl.ryzenx.com/files/win10pic1.jpg', $pathurl);
  20. }
  21. }
  22. if ($pathurl) {
  23. header('Content-Type: image/jpeg');
  24. header("Cache-Control: no-store, no-cache, must-revalidate");//强制不缓存
  25. header("Pragma: no-cache");//禁止本页被缓存
  26. @ob_end_clean();
  27. @readfile($pathurl);
  28. @flush();
  29. @ob_flush();
  30. exit();
  31. } else {
  32. exit('error');
  33. }
  34. function deleteDir($path_e) {
  35. if (is_dir($path_e)) {
  36. //扫描一个目录内的所有目录和文件并返回数组
  37. $dirs = scandir($path_e);
  38. foreach ($dirs as $dir) {
  39. //排除目录中的当前目录(.)和上一级目录(..)
  40. if ($dir != '.' && $dir != '..') {
  41. //如果是目录则递归子目录,继续操作
  42. $sonDir = $path_e.'/'.$dir;
  43. if (is_dir($sonDir)) {
  44. //递归删除
  45. deleteDir($sonDir);
  46. //目录内的子目录和文件删除后删除空目录
  47. @rmdir($sonDir);
  48. } else {
  49. //如果是文件直接删除
  50. @unlink($sonDir);
  51. }
  52. }
  53. }
  54. @rmdir($path_e);
  55. }
  56. }
  57. ?>