src/Charcoal/Property/FileProperty.php
public function dataUpload($fileData)
    {
        $filename = null;
        if (is_array($fileData)) {
            // retrieve tmp file from temp dir
            $tmpDir = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
            $tmpFile = $tmpDir.$fileData['id'];

            if (!file_exists($tmpFile)) {
                throw new Exception(
                    'File does not exists.'
                );
            }
            $fileContent = file_get_contents($tmpFile);
            $filename = (!empty($fileData['name'])) ? $fileData['name'] : null;
            // delete tmp file
            unlink($tmpFile);
        } else {
            $fileContent = file_get_contents($fileData);
        }

        if ($fileContent === false) {
            throw new Exception(
                'File content could not be decoded.'
            );
        }

        $info = new finfo(FILEINFO_MIME_TYPE);
        $this->setMimetype($info->buffer($fileContent));
        $this->setFilesize(strlen($fileContent));
        if (!$this->validateAcceptedMimetypes() || !$this->validateMaxFilesize()) {
            return '';
        }

        $target = $this->uploadTarget($filename);

        $ret = file_put_contents($target, $fileContent);
        if ($ret === false) {
            return '';
        } else {
            $basePath = $this->basePath();
            $target = str_replace($basePath, '', $target);

            return $target;
        }
    }
public function dataUpload($fileData)
    {
        $filename = null;
        if (is_array($fileData)) {
            // retrieve tmp file from temp dir
            $tmpDir = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
            $tmpFile = $tmpDir.$fileData['id'];

            if (!file_exists($tmpFile)) {
                throw new Exception(
                    'File does not exists.'
                );
            }
            $fileContent = file_get_contents($tmpFile);
            $filename = (!empty($fileData['name'])) ? $fileData['name'] : null;
            // delete tmp file
            unlink($tmpFile);
        } else {
            $fileContent = file_get_contents($fileData);
        }

        if ($fileContent === false) {
            throw new Exception(
                'File content could not be decoded.'
            );
        }

        $info = new finfo(FILEINFO_MIME_TYPE);
        $this->setMimetype($info->buffer($fileContent));
        $this->setFilesize(strlen($fileContent));
        if (!$this->validateAcceptedMimetypes() || !$this->validateMaxFilesize()) {
            return '';
        }

        $target = $this->uploadTarget($filename);

        $ret = file_put_contents($target, $fileContent);
        if ($ret === false) {
            return '';
        } else {
            $basePath = $this->basePath();
            $target = str_replace($basePath, '', $target);

            return $target;
        }
    }
public function dataUpload ( $ fileData ) { $ filename = null ; if ( is_array ( $ fileData ) ) { // retrieve tmp file from temp dir $ tmpDir = rtrim ( sys_get_temp_dir ( ) , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR ; $ tmpFile = $ tmpDir . $ fileData [ 'id' ] ; if ( ! file_exists ( $ tmpFile ) ) { throw new Exception ( 'File does not exists.' ) ; } $ fileContent = file_get_contents ( $ tmpFile ) ; $ filename = ( ! empty ( $ fileData [ 'name' ] ) ) ? $ fileData [ 'name' ] : null ; // delete tmp file unlink ( $ tmpFile ) ; } else { $ fileContent = file_get_contents ( $ fileData ) ; } if ( $ fileContent === false ) { throw new Exception ( 'File content could not be decoded.' ) ; } $ info = new finfo ( FILEINFO_MIME_TYPE ) ; $ this -> setMimetype ( $ info -> buffer ( $ fileContent ) ) ; $ this -> setFilesize ( strlen ( $ fileContent ) ) ; if ( ! $ this -> validateAcceptedMimetypes ( ) || ! $ this -> validateMaxFilesize ( ) ) { return '' ; } $ target = $ this -> uploadTarget ( $ filename ) ; $ ret = file_put_contents ( $ target , $ fileContent ) ; if ( $ ret === false ) { return '' ; } else { $ basePath = $ this -> basePath ( ) ; $ target = str_replace ( $ basePath , '' , $ target ) ; return $ target ; } }
Upload to filesystem, from data URI.

@param string $fileData The file data, raw.
@throws Exception If data content decoding fails.
@return string
Upload to filesystem from data URI .