コード例 #1
0
 protected function uploadImage()
 {
     global $wgRequest, $wgOut, $wgUser, $wgGroupPermissions;
     header('Content-type: application/json');
     $result = array();
     $fromPage = $wgRequest->getVal('viapage');
     $title = Title::newFromText($fromPage, NS_MAIN);
     if (!$title->exists()) {
         $result['error'] = "Error: No article {$fromPage} found to link image.";
         return $result;
     }
     $tempname = TempLocalImageFile::createTempFileName($fromPage);
     $file = new TempLocalImageFile(Title::newFromText($tempname, NS_IMAGE), RepoGroup::singleton()->getLocalRepo());
     $name = $wgRequest->getFileName('wpUploadImage', '', '');
     $file->upload($wgRequest->getFileTempName('wpUploadImage'), '', '');
     $filesize = $file->getSize();
     if (!$filesize) {
         $result['error'] = 'Error: We didn\'t get a file. Please try again.';
         return $result;
     } else {
         if ($file->getMediaType() != 'BITMAP') {
             $result['error'] = 'Error: Only images are accepted.';
             return $result;
         } elseif ($filesize > $this->maxFilesize) {
             $result['error'] = 'Error: Your file is too big (' . ImageUploadHandler::formatBytes($filesize) . '). Max file size is ' . ImageUploadHandler::formatBytes($this->maxFilesize) . '.';
             return $result;
         }
     }
     $prevPermissions = $wgGroupPermissions['*']['upload'];
     $wgGroupPermissions['*']['upload'] = true;
     $result = $this->insertImage($name, $tempname, $result);
     $wgGroupPermissions['*']['upload'] = $prevPermissions;
     if (!$result['error']) {
         // Successfully uploaded; add to DB
         $this->addToDB($result);
     }
     return $result;
 }
コード例 #2
0
ファイル: image_crud.php プロジェクト: kenmozi/codeigniter
 protected function _upload_file($upload_dir)
 {
     $reg_exp = '/(\\.|\\/)(gif|jpeg|jpg|png)$/i';
     $options = array('upload_dir' => $upload_dir . '/', 'param_name' => 'qqfile', 'upload_url' => base_url() . $upload_dir . '/', 'accept_file_types' => $reg_exp);
     $upload_handler = new ImageUploadHandler($options);
     $uploader_response = $upload_handler->post();
     if (is_array($uploader_response)) {
         foreach ($uploader_response as &$response) {
             unset($response->delete_url);
             unset($response->delete_type);
         }
         $upload_response = $uploader_response[0];
     } else {
         $upload_response = false;
     }
     if (!empty($upload_response)) {
         $ci =& get_instance();
         $ci->load->library('image_moo');
         $filename = $upload_response->name;
         $path = $upload_dir . '/' . $filename;
         /* Resizing to 1024 x 768 if its required */
         list($width, $height) = getimagesize($path);
         if ($width > 1024 || $height > 768) {
             $ci->image_moo->load($path)->resize(1024, 768)->save($path, true);
         }
         /* ------------------------------------- */
         return $filename;
     } else {
         return false;
     }
 }
コード例 #3
0
 protected function _upload_file($upload_dir)
 {
     $reg_exp = '/(\\.|\\/)(gif|jpeg|jpg|png)$/i';
     $options = array('upload_dir' => $upload_dir . '/', 'param_name' => 'qqfile', 'upload_url' => base_url() . $upload_dir . '/', 'accept_file_types' => $reg_exp);
     $upload_handler = new ImageUploadHandler($options);
     $uploader_response = $upload_handler->post();
     if (is_array($uploader_response)) {
         foreach ($uploader_response as &$response) {
             unset($response->delete_url);
             unset($response->delete_type);
         }
         $upload_response = $uploader_response[0];
     } else {
         $upload_response = false;
     }
     if (!empty($upload_response)) {
         $ci =& get_instance();
         $ci->load->library('image_moo');
         $filename = $upload_response->name;
         $path = $upload_dir . '/' . $filename;
         // hotfix to set max image size (configure from applicaiton/config/image_crud.php)
         $max_width = $ci->config->item('image_crud_max_width');
         $max_height = $ci->config->item('image_crud_max_height');
         list($width, $height) = getimagesize($path);
         if ($width > $max_width || $height > $max_height) {
             $ci->image_moo->load($path)->resize($max_width, $max_height)->save($path, true);
         }
         return $filename;
     } else {
         return false;
     }
 }