人人商城

checkattach.ctrl.php 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. set_time_limit(0);
  8. if($do == 'ftp') {
  9. require(IA_ROOT . '/framework/library/ftp/ftp.php');
  10. $ftp_config = array(
  11. 'hostname' => trim($_GPC['host']),
  12. 'username' => trim($_GPC['username']),
  13. 'password' => strexists($_GPC['password'], '*') ? $_W['setting']['remote']['ftp']['password'] : trim($_GPC['password']),
  14. 'port' => intval($_GPC['port']),
  15. 'ssl' => trim($_GPC['ssl']),
  16. 'passive' => trim($_GPC['pasv']),
  17. 'timeout' => intval($_GPC['overtime']),
  18. 'rootdir' => trim($_GPC['dir']),
  19. );
  20. $url = trim($_GPC['url']);
  21. $filename = 'MicroEngine.ico';
  22. $ftp = new Ftp($ftp_config);
  23. if (true === $ftp->connect()) {
  24. if ($ftp->upload(ATTACHMENT_ROOT .'images/global/'. $filename, $filename)) {
  25. load()->func('communication');
  26. $response = ihttp_get($url. '/'. $filename);
  27. if (is_error($response)) {
  28. message(error(-1, '配置失败,FTP远程访问url错误'),'','ajax');
  29. }
  30. if (intval($response['code']) != 200) {
  31. message(error(-1, '配置失败,FTP远程访问url错误'),'','ajax');
  32. }
  33. $image = getimagesizefromstring($response['content']);
  34. if (!empty($image) && strexists($image['mime'], 'image')) {
  35. message(error(0,'配置成功'),'','ajax');
  36. } else {
  37. message(error(-1, '配置失败,FTP远程访问url错误'),'','ajax');
  38. }
  39. } else {
  40. message(error(-1, '配置失败,FTP远程访问url错误'),'','ajax');
  41. }
  42. } else {
  43. message(error(-1, 'FTP服务器连接失败,请检查配置'),'','ajax');
  44. }
  45. }
  46. if ($do == 'oss') {
  47. load()->model('attachment');
  48. $key = $_GPC['key'];
  49. $secret = strexists($_GPC['secret'], '*') ? $_W['setting']['remote']['alioss']['secret'] : $_GPC['secret'];
  50. $bucket = $_GPC['bucket'];
  51. $buckets = attachment_alioss_buctkets($key, $secret);
  52. list($bucket, $url) = explode('@@', $_GPC['bucket']);
  53. $result = attachment_newalioss_auth($key, $secret, $bucket,$url);
  54. if (is_error($result)) {
  55. message(error(-1, 'OSS-Access Key ID 或 OSS-Access Key Secret错误,请重新填写'),'','ajax');
  56. }
  57. $ossurl = $buckets[$bucket]['location'].'.aliyuncs.com';
  58. if (!empty($_GPC['url'])) {
  59. if (!strexists($_GPC['url'], 'http://') && !strexists($_GPC['url'],'https://')) {
  60. $url = 'http://'. trim($_GPC['url']);
  61. } else {
  62. $url = trim($_GPC['url']);
  63. }
  64. $url = trim($url, '/').'/';
  65. } else {
  66. $url = 'http://'.$bucket.'.'.$buckets[$bucket]['location'].'.aliyuncs.com/';
  67. }
  68. load()->func('communication');
  69. $filename = 'MicroEngine.ico';
  70. $response = ihttp_request($url. '/'.$filename, array(), array('CURLOPT_REFERER' => $_SERVER['SERVER_NAME']));
  71. if (is_error($response)) {
  72. message(error(-1, '配置失败,阿里云访问url错误'),'','ajax');
  73. }
  74. if (intval($response['code']) != 200) {
  75. message(error(-1, '配置失败,阿里云访问url错误,请保证bucket为公共读取的'),'','ajax');
  76. }
  77. $image = getimagesizefromstring($response['content']);
  78. if (!empty($image) && strexists($image['mime'], 'image')) {
  79. message(error(0,'配置成功'),'','ajax');
  80. } else {
  81. message(error(-1, '配置失败,阿里云访问url错误'),'','ajax');
  82. }
  83. }
  84. if ($do == 'qiniu') {
  85. load()->model('attachment');
  86. $_GPC['secretkey'] = strexists($_GPC['secretkey'], '*') ? $_W['setting']['remote']['qiniu']['secretkey'] : $_GPC['secretkey'];
  87. $auth= attachment_qiniu_auth(trim($_GPC['accesskey']), trim($_GPC['secretkey']), trim($_GPC['bucket']));
  88. if (is_error($auth)) {
  89. message(error(-1, '配置失败,请检查配置。注:请检查存储区域是否选择的是和bucket对应<br/>的区域'), '', 'ajax');
  90. }
  91. load()->func('communication');
  92. $url = $_GPC['url'];
  93. $url = strexists($url, 'http') ? trim($url, '/') : 'http://'.trim($url, '/');
  94. $filename = 'MicroEngine.ico';
  95. $response = ihttp_request($url. '/'.$filename, array(), array('CURLOPT_REFERER' => $_SERVER['SERVER_NAME']));
  96. if (is_error($response)) {
  97. message(error(-1, '配置失败,七牛访问url错误'),'','ajax');
  98. }
  99. if (intval($response['code']) != 200) {
  100. message(error(-1, '配置失败,七牛访问url错误,请保证bucket为公共读取的'),'','ajax');
  101. }
  102. $image = getimagesizefromstring($response['content']);
  103. if (!empty($image) && strexists($image['mime'], 'image')) {
  104. message(error(0,'配置成功'),'','ajax');
  105. } else {
  106. message(error(-1, '配置失败,七牛访问url错误'),'','ajax');
  107. }
  108. }
  109. if ($do == 'cos') {
  110. load()->model('attachment');
  111. $url = $_GPC['url'];
  112. if (empty($url)) {
  113. $url = 'http://'.$_GPC['bucket'].'-'. $_GPC['appid'].'.cos.myqcloud.com';
  114. }
  115. $bucket = trim($_GPC['bucket']);
  116. $_GPC['secretkey'] = strexists($_GPC['secretkey'], '*') ? $_W['setting']['remote']['cos']['secretkey'] : $_GPC['secretkey'];
  117. if (!strexists($url, '//'.$bucket.'-') && strexists($url, '.cos.myqcloud.com')) {
  118. $url = 'http://'.$bucket.'-'.trim($_GPC['appid']).'.cos.myqcloud.com';
  119. }
  120. $auth= attachment_cos_auth(trim($_GPC['bucket']), trim($_GPC['appid']), trim($_GPC['secretid']), trim($_GPC['secretkey']), $_GPC['local']);
  121. if (is_error($auth)) {
  122. message(error(-1, $auth['message']), '', 'ajax');
  123. }
  124. load()->func('communication');
  125. $url = strexists($url, 'http') ? trim($url, '/') : 'http://'.trim($url, '/');
  126. $filename = 'MicroEngine.ico';
  127. $response = ihttp_request($url. '/'.$filename, array(), array('CURLOPT_REFERER' => $_SERVER['SERVER_NAME']));
  128. if (is_error($response)) {
  129. message(error(-1, '配置失败,腾讯cos访问url错误'),'','ajax');
  130. }
  131. if (intval($response['code']) != 200) {
  132. message(error(-1, '配置失败,腾讯cos访问url错误,请保证bucket为公共读取的'),'','ajax');
  133. }
  134. $image = getimagesizefromstring($response['content']);
  135. if (!empty($image) && strexists($image['mime'], 'image')) {
  136. message(error(0,'配置成功'),'','ajax');
  137. } else {
  138. message(error(-1, '配置失败,腾讯cos访问url错误'),'','ajax');
  139. }
  140. }