/** * Handles uploads from media manager. * * @since 4.0 * @access public * @param string * @return */ public function upload() { // Ensure that the user is logged in EB::requireLogin(); // Only allowed users who are allowed to upload images if (!$this->acl->get('upload_image')) { $this->output(EB::exception('COM_EASYBLOG_NOT_ALLOWED', EASYBLOG_MSG_ERROR)); } // Load up media manager $mm = EB::mediamanager(); // Get uri $key = $this->input->getRaw('key'); // Get the target folder $placeId = EBMM::getUri($key); // Get the file input $file = $this->input->files->get('file'); // Check if the file is really allowed to be uploaded to the site. $state = EB::image()->canUploadFile($file); if ($state instanceof Exception) { return $this->output($state); } // MM should check if the user really has access to upload to the target folder $allowed = EBMM::hasAccess($placeId); if ($allowed instanceof Exception) { return $this->output($allowed); } // Check the image name is it got contain space, if yes need to replace to '-' $fileName = $file['name']; $file['name'] = str_replace(' ', '-', $fileName); // Upload the file now $file = $mm->upload($file, $placeId); // Response object is intended to also include // other properties like status message and status code. // Right now it only inclues the media item. $response = new stdClass(); $response->media = EBMM::getMedia($file->uri); return $this->output($response); }
public function uploadImage($key) { // Load up media manager $mm = EB::mediamanager(); // Get the target folder $placeId = EBMM::getUri($key); // Get the file input $file = JRequest::getVar('file', '', 'FILES', 'array'); // Check if the file is really allowed to be uploaded to the site. $state = EB::image()->canUploadFile($file); if ($state instanceof Exception) { //add error code return $state; //return $this->output($state); } // MM should check if the user really has access to upload to the target folder $allowed = EBMM::hasAccess($placeId); if ($allowed instanceof Exception) { //add error code return $state; //return $this->output($allowed); } // Check the image name is it got contain space, if yes need to replace to '-' $fileName = $file['name']; $file['name'] = str_replace(' ', '-', $fileName); // Upload the file now $file = $mm->upload($file, $placeId); // Response object is intended to also include // other properties like status message and status code. // Right now it only inclues the media item. $response = new stdClass(); $response->media = EBMM::getMedia($file->uri); //code for future use //header('Content-type: text/x-json; UTF-8'); //$resp = json_encode($response, JSON_HEX_TAG); return $response; }