Example #1
0
 public function sendToImgUr(&$img, &$model, $data, $type = 'data')
 {
     $timeout = 30;
     $curl = curl_init();
     // $data is file data
     if ($type == 'data') {
         $pvars = array('image' => base64_encode($data), 'key' => HmnConstantDefine::IMGUR_API_KEY);
     } else {
         $pvars = array('image' => $data, 'key' => HmnConstantDefine::IMGUR_API_KEY);
     }
     curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
     curl_setopt($curl, CURLOPT_URL, 'http://api.imgur.com/2/upload.json');
     curl_setopt($curl, CURLOPT_POST, 1);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_POSTFIELDS, $pvars);
     $xml = curl_exec($curl);
     curl_close($curl);
     if ($xml) {
         $xml = json_decode($xml);
         if (isset($xml->error)) {
             $model->addError('image', 'Có lỗi trong quá trình upload');
         } else {
             $model = new UploadImageForm();
             $img = $xml->upload->links->original;
         }
     } else {
         $model->addError('image', 'Có lỗi trong quá trình upload');
     }
 }
Example #2
0
 public function index($params)
 {
     $pluginKey = $params['pluginKey'];
     $this->initMenu($params);
     $this->addComponent('menu', $this->menu);
     $this->menu->getElement('upload')->setActive(true);
     $form = new UploadImageForm();
     if (!empty($_POST['command']) && $_POST['command'] == 'image-upload') {
         UploadImageForm::process($pluginKey, $params);
     }
     $this->assign('maxSize', OW::getConfig()->getValue('base', 'tf_max_pic_size'));
     $this->addForm($form);
 }