FileAction.class.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Fanwe 方维p2p借贷系统
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: 云淡风轻(1956838968@qq.com)
  8. // +----------------------------------------------------------------------
  9. class FileAction extends CommonAction{
  10. public function do_upload()
  11. {
  12. if(intval($_REQUEST['upload_type'])==0){
  13. $result = $this->uploadFile();
  14. }
  15. else{
  16. $result = $this->uploadImage($_REQUEST['thumb']);
  17. }
  18. if($result['status'] == 1)
  19. {
  20. $list = $result['data'];
  21. if(intval($_REQUEST['upload_type'])==0)
  22. $file_url = ".".$list[0]['recpath'].$list[0]['savename'];
  23. else{
  24. $file_url = ".".$list[0]['bigrecpath'].$list[0]['savename'];
  25. $thumb_url = ".".$list[0]['thumbpath'].$list[0]['savename'];
  26. }
  27. /*$html = '<html>';
  28. $html.= '<head>';
  29. $html.= '<title>Insert Image</title>';
  30. $html.= '<meta http-equiv="content-type" content="text/html; charset=utf-8">';
  31. $html.= '</head>';
  32. $html.= '<body>';
  33. $html.= '<script type="text/javascript">';
  34. $html.= 'parent.parent.KE.plugin["image"].insert("' . $_POST['id'] . '", "' . $file_url . '","' . $_POST['imgTitle'] . '","' . $_POST['imgWidth'] . '","' . $_POST['imgHeight'] . '","' . $_POST['imgBorder'] . '","' . $_POST['align'] . '");';
  35. $html.= '</script>';
  36. $html.= '</body>';
  37. $html.= '</html>';
  38. echo $html;*/
  39. $public_url=$file_url;
  40. if($GLOBALS['distribution_cfg']['OSS_TYPE']&&$GLOBALS['distribution_cfg']['OSS_TYPE']!='NONE')
  41. {
  42. syn_to_remote_image_server($file_url);
  43. }
  44. if($GLOBALS['distribution_cfg']['OSS_TYPE']&&$GLOBALS['distribution_cfg']['OSS_TYPE']=='ALI_OSS'){
  45. $file_url=get_spec_image($public_url);
  46. }else{
  47. $file_url=str_replace("./public/",file_domain()."/public/",$file_url);
  48. }
  49. save_log($file_url."UPLOAD SUCCESS",1);
  50. ajax_file_return(array('error' => 0, 'url' => $file_url,'public_url'=>$public_url,'thumb_url'=>$thumb_url));
  51. }
  52. else
  53. {
  54. //echo "<script>alert('".$result['info']."');</script>";
  55. save_log("UPLOAD FAILED",0);
  56. ajax_file_return(array('error' => 1, 'message' => $result['info']));
  57. }
  58. }
  59. public function do_cut_upload(){
  60. require_once APP_ROOT_PATH."system/utils/crop.php";
  61. $width = floatval($_REQUEST['w']);
  62. $height = floatval($_REQUEST['h']);
  63. $dst = strim($_REQUEST['dst']);
  64. $crop = new CropAvatar($_POST['avatar_src'], $_POST['avatar_data'], $_FILES['avatar_file'],$width,$height);
  65. $response = array(
  66. 'state' => 200,
  67. 'message' => $crop -> getMsg(),
  68. 'result' => $crop -> getResult(),
  69. 'dst' => $dst
  70. );
  71. echo json_encode($response);
  72. }
  73. public function do_upload_img()
  74. {
  75. if(intval($_REQUEST['upload_type'])==0)
  76. $result = $this->uploadFile();
  77. else
  78. $result = $this->uploadImage();
  79. if($result['status'] == 1)
  80. {
  81. $list = $result['data'];
  82. if(intval($_REQUEST['upload_type'])==0)
  83. $file_url = ".".$list[0]['recpath'].$list[0]['savename'];
  84. else
  85. $file_url = ".".$list[0]['bigrecpath'].$list[0]['savename'];
  86. /*$html = '<html>';
  87. $html.= '<head>';
  88. $html.= '<title>Insert Image</title>';
  89. $html.= '<meta http-equiv="content-type" content="text/html; charset=utf-8">';
  90. $html.= '</head>';
  91. $html.= '<body>';
  92. $html.= '<script type="text/javascript">';
  93. //$html.='alert("'.$_POST['id'].'");';
  94. //$html.='alert(parent.parent.document.getElementById("'.$_POST['id'].'").value);';
  95. //$html.='parent.parent.document.getElementById("'.$_POST['id'].'").value="'.$file_url.'";';
  96. $html.= 'parent.parent.KE.plugin["upload_image"].insert("' . $_POST['id'] . '", "' . $file_url . '","' . $_POST['imgTitle'] . '","' . $_POST['imgWidth'] . '","' . $_POST['imgHeight'] . '","' . $_POST['imgBorder'] . '","' . $_POST['align'] . '");';
  97. $html.= '</script>';
  98. $html.= '</body>';
  99. $html.= '</html>';
  100. echo $html;*/
  101. admin_ajax_return(array('error' => 0, 'url' => str_replace("./public/",SITE_DOMAIN.APP_ROOT."/public/",$file_url)));
  102. }
  103. else
  104. {
  105. //echo "<script>alert('".$result['info']."');</script>";
  106. admin_ajax_return(array('error' => 1, 'message' => $result['info']));
  107. }
  108. }
  109. public function deleteImg()
  110. {
  111. B('FilterString');
  112. $ajax = intval($_REQUEST['ajax']);
  113. $file = $_REQUEST['file'];
  114. $file = explode("..",$file);
  115. $file = $file[4];
  116. $file = substr($file,1);
  117. @unlink(get_real_path().$file);
  118. if(app_conf("PUBLIC_DOMAIN_ROOT")!='')
  119. {
  120. $syn_url = app_conf("PUBLIC_DOMAIN_ROOT")."/es_file.php?username=".app_conf("IMAGE_USERNAME")."&password=".app_conf("IMAGE_PASSWORD")."&path=".$file."&act=1";
  121. @file_get_contents($syn_url);
  122. }
  123. save_log(l("DELETE_SUCCESS"),1);
  124. $this->success(l("DELETE_SUCCESS"),$ajax);
  125. }
  126. }
  127. ?>