| 1: | <?php
|
| 2: |
|
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | |
| 35: | |
| 36: |
|
| 37: |
|
| 38: | class SystemFineImUploadHandler extends SystemFineUploadHandler
|
| 39: | {
|
| 40: | |
| 41: | |
| 42: | |
| 43: |
|
| 44: | public function __construct(\stdClass $claims)
|
| 45: | {
|
| 46: | parent::__construct($claims);
|
| 47: | $this->allowedMimeTypes = array('image/gif', 'image/jpeg', 'image/png');
|
| 48: | $this->allowedExtensions = array('gif', 'jpeg', 'jpg', 'png');
|
| 49: | }
|
| 50: |
|
| 51: | protected function storeUploadedFile($target, $mimeType, $uuid)
|
| 52: | {
|
| 53: |
|
| 54: | $imgcatHandler = xoops_getHandler('imagecategory');
|
| 55: | $imgcat = $imgcatHandler->get($this->claims->cat);
|
| 56: |
|
| 57: | $pathParts = pathinfo($this->getName());
|
| 58: |
|
| 59: | $imageName = uniqid('img', true) . '.' . strtolower($pathParts['extension']);
|
| 60: | $imageNicename = str_replace(array('_','-'), ' ', $pathParts['filename']);
|
| 61: | $imagePath = XOOPS_ROOT_PATH . '/uploads/images/' . $imageName;
|
| 62: |
|
| 63: | $fbinary = null;
|
| 64: | if ($imgcat->getVar('imgcat_storetype') === 'db') {
|
| 65: | $fbinary = file_get_contents($_FILES[$this->inputName]['tmp_name']);
|
| 66: | } else {
|
| 67: | if (false === move_uploaded_file($_FILES[$this->inputName]['tmp_name'], $imagePath)) {
|
| 68: | return false;
|
| 69: | }
|
| 70: | }
|
| 71: |
|
| 72: |
|
| 73: | $imageHandler = xoops_getHandler('image');
|
| 74: | $image = $imageHandler->create();
|
| 75: |
|
| 76: | $image->setVar('image_nicename', $imageNicename);
|
| 77: | $image->setVar('image_mimetype', $mimeType);
|
| 78: | $image->setVar('image_created', time());
|
| 79: | $image->setVar('image_display', 1);
|
| 80: | $image->setVar('image_weight', 0);
|
| 81: | $image->setVar('imgcat_id', $this->claims->cat);
|
| 82: | if ($imgcat->getVar('imgcat_storetype') === 'db') {
|
| 83: | $image->setVar('image_body', $fbinary, true);
|
| 84: | } else {
|
| 85: | $image->setVar('image_name', 'images/' . $imageName);
|
| 86: | }
|
| 87: | if (!$imageHandler->insert($image)) {
|
| 88: | return array(
|
| 89: | 'error' => sprintf(_FAILSAVEIMG, $image->getVar('image_nicename'))
|
| 90: | );
|
| 91: | }
|
| 92: | return array('success'=> true, "uuid" => $uuid);
|
| 93: | }
|
| 94: | }
|
| 95: | |