Datatypes\jQueryFileUpload\Editor::save PHP Method

save() public method

Save upload editor
public save ( ) : void
return void
    public function save()
    {
        $fileClass = new File();
        $fileClass->load($this->getProperty(), $this->getDatatype()->getDocument());
        $post = $this->getRequest()->getPost();
        $values = $post->get($this->getName(), array());
        $parameters = $this->getConfig();
        $arrayValues = array();
        if (!empty($values) and is_array($values)) {
            foreach ($values as $idx => $value) {
                if (empty($value['name'])) {
                    continue;
                }
                $file = $fileClass->getPath() . '/' . $value['name'];
                if (file_exists($file)) {
                    $const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME;
                    $finfo = finfo_open($const);
                    // return mimetype extension
                    if (!in_array(finfo_file($finfo, $file), $parameters['mime_list'])) {
                        unlink($file);
                    } else {
                        $fileInfo = @getimagesize($file);
                        $arrayValues[] = array('value' => $value['name'], 'width' => empty($fileInfo[0]) ? 0 : $fileInfo[0], 'height' => empty($fileInfo[1]) ? 0 : $fileInfo[1], 'html' => empty($fileInfo[2]) ? '' : $fileInfo[2], 'mime' => empty($fileInfo['mime']) ? '' : $fileInfo['mime']);
                    }
                    finfo_close($finfo);
                }
            }
            $returnValues = serialize($arrayValues);
        }
        $this->setValue(empty($returnValues) ? null : $returnValues);
    }

Usage Example

Beispiel #1
0
 /**
  * Test
  *
  * @return void
  */
 public function testSave()
 {
     copy(__DIR__ . '/_files/test-source.bmp', __DIR__ . '/_files/test.bmp');
     $this->object->getRequest()->getPost()->set($this->object->getName(), array(array('name' => ''), array('name' => '../tests/library/Datatypes/jQueryFileUpload/_files/test.jpg'), array('name' => '../tests/library/Datatypes/jQueryFileUpload/_files/test.bmp')));
     $this->object->setConfig(array('is_multiple' => true, 'mime_list' => array('image/gif', 'image/jpeg', 'image/png')));
     $this->object->save();
     $result = $this->object->getValue();
     $this->assertInternalType('string', $this->object->getValue());
 }