ali_oss_syn.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Fanwe 方维直播系统
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: 云淡风轻(1956838968@qq.com)
  8. // +----------------------------------------------------------------------
  9. //同步本地文件至阿里oss
  10. define("FILE_PATH","/tool"); //文件目录,空为根目录
  11. require_once '../system/system_init.php';
  12. require '../public/directory_init.php';
  13. set_time_limit(0);
  14. $paths = array(
  15. "public/attachment/",
  16. "public/avatar/",
  17. "public/emoticons/",
  18. );
  19. function syn_path($service,$bucket,$path)
  20. {
  21. if ( $dir = opendir( $path ) )
  22. {
  23. while ( $file = readdir( $dir ) )
  24. {
  25. $check = is_dir( $path. $file );
  26. if ( !$check )
  27. {
  28. if(!preg_match("/_(\d+)x(\d+)/i",$file,$matches))
  29. {
  30. //同步
  31. $file_dir = str_replace(APP_ROOT_PATH, "", $path);
  32. $object = $file_dir.$file;
  33. $file_path = $path. $file;
  34. $re = $service->upload_file_by_file($bucket,$object,$file_path);
  35. }
  36. }
  37. else
  38. {
  39. if($file!='.'&&$file!='..')
  40. {
  41. syn_path($service,$bucket,$path.$file."/");
  42. }
  43. }
  44. }
  45. closedir( $dir );
  46. }
  47. }
  48. if($GLOBALS['distribution_cfg']['OSS_TYPE']=="ALI_OSS")
  49. {
  50. require_once APP_ROOT_PATH."system/alioss/sdk.class.php";
  51. $oss_sdk_service = new ALIOSS();
  52. //设置是否打开curl调试模式
  53. $oss_sdk_service->set_debug_mode(true);
  54. $bucket = $GLOBALS['distribution_cfg']['OSS_BUCKET_NAME'];
  55. foreach($GLOBALS['paths'] as $path)
  56. {
  57. syn_path($oss_sdk_service,$bucket,APP_ROOT_PATH.$path);
  58. }
  59. }
  60. ?>