Img.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Img extends Admin_Controller {
  3. function __construct(){
  4. parent::__construct();
  5. $this->load->library('upload');
  6. }
  7. public function _remap($arg)
  8. {
  9. if($arg == 'textimg')
  10. {
  11. $this->_textimg();
  12. }
  13. else if($arg == 'thumb')
  14. {
  15. $this->_thumb();
  16. }
  17. else
  18. {
  19. $this->_index();
  20. }
  21. }
  22. //上传图片
  23. public function _index()
  24. {
  25. $dir = '/data/img/'.date('Ymd',time()).'/';
  26. $config['upload_path'] = '.'.$dir ;
  27. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  28. $config['allowed_types'] = '*';
  29. $config['max_size'] = 51200;
  30. $this->load->library('upload', $config);
  31. $this->upload->initialize($config);
  32. if ($this->upload->do_upload('userfile'))
  33. {
  34. $full_path = $dir.$this->upload->data('file_name');
  35. echo json_encode(array('ok'=>1,'lx'=>$this->upload->data('file_ext'),'filename'=>$full_path));
  36. }
  37. else
  38. {
  39. echo json_encode(array('msg'=>$this->upload->display_errors()));
  40. }
  41. }
  42. //编辑器上传图
  43. public function _textimg()
  44. {
  45. $dir = '/data/img/'.date('Ymd',time()).'/';
  46. $config['upload_path'] = '.'.$dir ;
  47. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  48. $config['allowed_types'] = 'gif|jpg|png';
  49. $config['max_size'] = 51200;
  50. $field_name = "upfile";
  51. $this->load->library('upload', $config);
  52. $this->upload->initialize($config);
  53. if ($this->upload->do_upload($field_name))
  54. {
  55. $name = $this->upload->data('file_name'); //重命名后的图片名称+后缀
  56. $client_name = $this->upload->data('client_name');//提交的图片名称+后缀
  57. $file_ext = $this->upload->data('file_ext');//图片后缀
  58. $file_size = $this->upload->data('file_size');//图片大小
  59. $full_path = $dir.$this->upload->data('file_name');//图片上传的完整路径+名称+后缀
  60. echo json_encode(array('errno'=>0,'data'=>array('url'=>'http://a.wepolicy.cn'.$full_path)));
  61. }
  62. else
  63. {
  64. echo json_encode(array('errno'=>1,'data'=>array('message'=>$this->upload->display_errors())));
  65. }
  66. }
  67. public function _thumb()
  68. {
  69. $this->load->library('thumb');
  70. $test=new thumb();
  71. $src = FCPATH.$this->input->get('src');
  72. $w = $this->input->get('w');
  73. $h = $this->input->get('h');
  74. $a = $this->input->get('a');
  75. $test->SetVar($src,'link');
  76. $test->PRorate($src,$w,$h);
  77. }
  78. }