変数上のデータをファイルとして出力します。

@param	mixed	$data		ファイルとして出力するデータ
@param	string	$file_name	出力するファイル名
@param	string	$mime_type	MIME type
@param	string	$options	オプション
192407
public static function SendDataAsFile ($data, $file_name, $mime_type = null, $options = []) {
		//==============================================
		//オプション展開
		//==============================================
		$filename_from_charset	= $options['from_charset']			?? Encoding::UTF_8;
		$filename_to_charset	= $options['to_charset']			?? Encoding::SJIS;
		$chunk_size				= $options['chunk_size']			?? static::CHUNK_SIZE;
		$content_disposition	= $options['content_disposition']	?? static::CONTENT_DISPOSITION_ATTACHMENT;

		//==============================================
		//データサイズ取得
		//==============================================
		$file_size = strlen($data);

		//==============================================
		//mime type確定
		//==============================================
		if ($mime_type === null) {
			$ext = pathinfo($file_name, \PATHINFO_EXTENSION);
			$mime_type = self::GetMimeTypeMapForExt()[$ext] ?? self::MIME_TYPE_BINARY;
		}

		//==============================================
		//ファイル送信開始
		//==============================================
		//HTTP ResponseHeaderの出力
		foreach (static::GetHttpHeaderContentDispositionAttachment(
			$file_name,
			$file_size,
			$mime_type,
			$content_disposition,
			$filename_to_charset,
			$filename_from_charset
		) as $header) {
			header(str_replace(["\r", "\n"], '', $header));
		}

		//----------------------------------------------
		//実処理の開始
		//----------------------------------------------
		//既存の出力を全て送信
		OutputBuffer::Clean();
		flush();

		//timeout引き延ばし処理：実行開始秒
		$split_time = time();

		//チャンクサイズごとに送信
		for ($i = 0;$i < $file_size;$i++) {
			print $data[$i];
			flush();
					//3秒以上経過ごとにタイムリミットを延長する
			if (time() - $split_time > 3) {
				set_time_limit(time() - $split_time);
			}
		}

		//==============================================
		//処理の終了
		//==============================================
	}
1283552
public function attachment($file, $name = null, $mime = null) {

		if(true === is_string($file)) {
			$file = new File($file);
		}

		if(false === $file instanceof File) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string or sFire\System\File, "%s" given', __METHOD__, gettype($file)), E_USER_ERROR);
		}

		if(false === $file -> isReadable()) {
			return trigger_error(sprintf('Argument 1 passed to %s() must existing and readable file', __METHOD__), E_USER_ERROR);
		}

		if(null !== $name && false === is_string($name)) {
			return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($name)), E_USER_ERROR);
		}

		if(null !== $mime && false === is_string($mime)) {
			return trigger_error(sprintf('Argument 3 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($mime)), E_USER_ERROR);
		}

		if(false === isset($this -> headers['files'])) {
			$this -> headers['files'] = [];
		}

		$name = null !== $name ? $name : $file -> entity() -> getBasename();
		$mime = null !== $mime ? $mime : $file -> getMime();

		$this -> headers['files'][] = (object) ['file' => $file, 'name' => $name, 'mime' => $mime];

		return $this;
	}
436319
public function insert($data, $options = [])
    {
        return $this->database->createCommand()->insert($this->name, $data, $options);
    }
720034
private function addFile(array &$files, string $fieldName, string $filename, string $tmpPath, string $mimeType, bool $err): void
    {
        $data = [
            'type' => $mimeType ?: 'application/octet-stream',
            'name' => $filename,
            'tmp_name' => $tmpPath,
            'error' => $err ? UPLOAD_ERR_CANT_WRITE : UPLOAD_ERR_OK,
            'size' => filesize($tmpPath),
        ];

        $parts = preg_split('|(\[[^\]]*\])|', $fieldName, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
        $count = count($parts);
        if (1 === $count) {
            $files[$fieldName] = $data;
        } else {
            $current = &$files;
            foreach ($parts as $i => $part) {
                if ($part === '[]') {
                    $current[] = $data;
                    continue;
                }

                $trimmedMatch = trim($part, '[]');
                if ($i === $count -1) {
                    $current[$trimmedMatch] = $data;
                } else {
                    $current = &$current[$trimmedMatch];
                }
            }
        }
    }
958720
public function createNamedFormBuilder($name = 'form', $data = null, array $options = array())
    {
        return $this->getFormFactory()->createNamedBuilder($name, FormType::class, $data, $options);
    }
906588
public function attachData($data, $options=[]) {
		$attachment = \Swift_Attachment::newInstance($data);
		if(isset($options['filename']))
			$attachment->setFilename($options['filename']);
		if(isset($options['mime']))
			$attachment->setContentType($options['mime']);
		return $this->attach($attachment);
	}
1073604
public function widget($name, array $data = [], array $options = [])
    {
        $parts = explode('::', $name);
        $name = $parts[0] . 'Widgets';
        $name = empty($parts[1]) ? $name : sprintf('%s::%s', $name, $parts[1]);

        return $this->getView()->cell($name, $data, $options);
    }
1075821
private function verifyMimeType($mime_type)
    {
        $allowed = $this->config['allowed_mime_types'];
        if (! empty($allowed) && ! in_array(strtolower($mime_type), $allowed)) {
            throw FileNotSupportedException::mimeRestricted(strtolower($mime_type), $allowed);
        }

        return $mime_type;
    }
28818
public function createForm($name, $type = "form", array $data = array(), array $options = array())
    {
        $options = array_merge(
            [
                "csrf_protection" => false,
            ],
            $options
        );

        return parent::createForm($name, $type, $data, $options);
    }
248167
public function addFile($file, $name = null, $mime = null) {

		if('post' !== $this -> method) {
			return trigger_error('File uploads are only supported with POST request method', E_USER_ERROR);
		}

		if(false === $file instanceof File && false === is_string($file)) {
            return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string or instance of sFire\\System\\File, "%s" given', __METHOD__, gettype($file)), E_USER_ERROR);
        }

        if(null !== $name && false === is_string($name)) {
            return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($name)), E_USER_ERROR);
        }

		if(null !== $mime && false === is_string($mime)) {
			return trigger_error(sprintf('Argument 3 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($mime)), E_USER_ERROR);
		}

		if(true === is_string($file)) {
			$file = new File($file);
		}

		if(false === $file -> isReadable()) {
			return trigger_error(sprintf('File %s passed to %s() is not readable', $file -> entity() -> getBasepath(), __METHOD__), E_USER_ERROR);
		}

		if(null === $name) {
			$name = $file -> entity() -> getBasename();
		}

		if(null === $mime) {
			$mime = $file -> getMime();
		}

		$this -> files[] = (object) ['file' => $file, 'name' => $name, 'mime' => $mime];

		return $this;
	}
345746
public function file($name, $label = null, array $options = [])
    {
        $label = $this->getLabelTitle($label, $name);

        $options = array_merge(['class' => 'filestyle', 'data-buttonBefore' => 'true'], $options);

        $options = $this->getFieldOptions($options, $name);
        $inputElement = $this->form->input('file', $name, null, $options);

        $wrapperOptions = $this->isHorizontal() ? ['class' => $this->getRightColumnClass()] : [];
        $wrapperElement = '<div' . $this->html->attributes($wrapperOptions) . '>' . $inputElement . $this->getFieldError($name) . $this->getHelpText($name, $options) . '</div>';

        return $this->getFormGroup($name, $label, $wrapperElement);
    }
355263
public function loadString(string $machine_type, string $data_string, array $options = [], string $filename = null)
	{
		return Utils::parse_json_string($data_string, $filename);
	}
837639
private function writeData(array $data, array $options)
    {
        $this->write(json_encode($data, isset($options['json_encoding']) ? $options['json_encoding'] : 0));
    }
1207673
function process( $mimeData, $parameters = array() )
    {
        $printInfo = false;
        if ( isset( $parameters['print_info'] ) )
            $printInfo = $parameters['print_info'];

        $filename = $mimeData['url'];
        $fd = fopen( $filename, 'rb' );
        if ( $fd )
        {
            $blockTypes = array( 0x21 => 'Exension Introducer',
                                 0x2c => 'Image Descriptor',
                                 0x3b => 'Trailer' );
            $extensionLabels = array( 0xf9 => 'Graphical Control Extension',
                                      0xff => 'Application Extension',
                                      0xfe => 'Comment Extension' );
            // Read GIF header
            $data = fread( $fd, 6 );
            if ( $data == 'GIF87a' or
                 $data == 'GIF89a' )
            {
                $info = array();

                $info['version'] = substr( $data, 3 );
                $info['frame_count'] = 0;
                $info['mode'] = eZImageAnalyzer::MODE_INDEXED;
                $offset = 6;

                $info['animation_timer'] = false;
                $info['animation_timer_type'] = eZImageAnalyzer::TIMER_HUNDRETHS_OF_A_SECOND;

                $info['comment_list'] = array();

                $info['transparency_type'] = eZImageAnalyzer::TRANSPARENCY_OPAQUE;

                // Read Logical Screen Descriptor
                $data = fread( $fd, 7 );
                $offset += 7;

                $lsdFields = ord( $data[4] );

                $globalColorCount = 0;
                $globalColorTableSize = 0;
                if ( $lsdFields >> 7 )
                {
                    $globalColorCount = ( 1 << ( ( $lsdFields & 0x07 ) + 1) );
                    $globalColorTableSize = $globalColorCount * 3;
                }

                $info['color_count'] = $globalColorCount;

                $info['width'] = ( ord( $data[1] ) << 8 ) + ord( $data[0] );
                $info['height'] = ( ord( $data[3] ) << 8 ) + ord( $data[2] );


                if ( $globalColorTableSize )
                {
                    fseek( $fd, $globalColorTableSize, SEEK_CUR );
                    $offset += $globalColorTableSize;
                }
                if ( $printInfo )
                    print( "Global color table size=$globalColorTableSize\n" );

                $done = false;
                while ( !$done )
                {
                    $data = fread( $fd, 1 );
                    $offset += 1;
                    $blockType = ord( $data[0] );
                    if ( $printInfo )
                    {
                        print( "Block type=0x" . dechex( $blockType ) );
                        if ( isset( $blockTypes[$blockType] ) )
                            print( " (" . $blockTypes[$blockType] . ")" );
                        print( "\n" );
                    }
                    if ( $blockType == 0x21 ) // Extension Introducer
                    {
                        $data .= fread( $fd, 1 );
                        $offset += 1;
                        $extensionLabel = ord( $data[1] );
                        if ( $printInfo )
                        {
                            print( "> " . "Extension label=0x" . dechex( $extensionLabel ) );
                            if ( isset( $extensionLabels[$extensionLabel] ) )
                                print( " (" . $extensionLabels[$extensionLabel] . ")" );
                            print( "\n" );
                        }
                        if ( $extensionLabel == 0xf9 ) // Graphical Control Extension
                        {
                            $data = fread( $fd, 5 + 1 );
                            $info['animation_timer'] = ( ord( $data[3] ) << 8 ) + ord( $data[2] );
                            $gceFlags = ord( $data[1] );
                            if ( $gceFlags & 0x01 )
                                $info['transparency_type'] = eZImageAnalyzer::TRANSPARENCY_TRANSPARENT;
                            $offset += 5 + 1;
                        }
                        else if ( $extensionLabel == 0xff ) // Application Extension
                        {
                            $data = fread( $fd, 12 );
                            if ( $printInfo )
                            {
                                $applicationIdentifier = substr( $data, 1, 8 );
                                $applicationAuthentication = substr( $data, 1 + 8, 3 );
                                print( ">> Application identifier: $applicationIdentifier\n" );
                                print( ">> Application authentication: $applicationAuthentication\n" );
                            }
                            $offset += 12;

                            $dataBlockDone = false;
                            while ( !$dataBlockDone )
                            {
                                $data = fread( $fd, 1 );
                                $offset += 1;
                                $blockBytes = ord( $data[0] );
                                if ( $printInfo )
                                    print( ">> Application Block size=$blockBytes\n" );
                                if ( $blockBytes )
                                {
                                    fseek( $fd, $blockBytes, SEEK_CUR );
                                    $offset += $blockBytes;
                                }
                                else
                                {
                                    if ( $printInfo )
                                        print( ">> GIF application blocks terminated by 0 image block\n" );
                                    $dataBlockDone = true;
                                }
                            }
                        }
                        else if ( $extensionLabel == 0xfe ) // Comment Extension
                        {
                            $commentBlockDone = false;
                            $comment = false;
                            while ( !$commentBlockDone )
                            {
                                $data = fread( $fd, 1 );
                                $offset += 1;
                                $blockBytes = ord( $data[0] );
                                if ( $printInfo )
                                    print( ">> Comment Block size=$blockBytes\n" );
                                if ( $blockBytes )
                                {
                                    $data = fread( $fd, $blockBytes );
                                    if ( $printInfo )
                                        print( $data );
                                    $comment .= $data;
                                    $offset += $blockBytes;
                                }
                                else
                                {
                                    if ( $printInfo )
                                        print( ">> GIF comment blocks terminated by 0 image block\n" );
                                    $commentBlockDone = true;
                                }
                            }
                            if ( $comment )
                                $info['comment_list'][] = $comment;
                        }
                        else
                        {
                            if ( $printInfo )
                                print( "> Unknown extension label, aborting\n" );
                            $done = true;
                        }
                    }
                    else if ( $blockType == 0x2c ) // Image Descriptor
                    {
                        $info['frame_count'] += 1;
                        $data .= fread( $fd, 9 );
                        $localColorTableSize = 0;
                        $localColorCount = 0;
                        $idFields = ord( $data[9] );
                        if ( $idFields >> 7 ) // Local Color Table
                        {
                            $localColorCount = ( 1 << ( ( $idFields & 0x07 ) + 1) );
                            $localColorTableSize = $localColorCount * 3;
                        }
                        if ( $localColorCount > $globalColorCount )
                            $info['color_count'] = $localColorCount;

                        if ( $localColorTableSize )
                        {
                            fseek( $fd, $localColorTableSize, SEEK_CUR );
                            $offset += $localColorTableSize;
                        }
                        if ( $printInfo )
                            print( ">> Local color table size=$localColorTableSize\n" );

                        $lzwCodeSize = fread( $fd, 1 ); // LZW Minimum Code Size
                        $offset += 1;

                        $dataBlockDone = false;
                        while ( !$dataBlockDone )
                        {
                            $data = fread( $fd, 1 );
                            $offset += 1;
                            $blockBytes = ord( $data[0] );
                            if ( $printInfo )
                                print( ">> Block size=$blockBytes\n" );
                            if ( $blockBytes )
                            {
                                fseek( $fd, $blockBytes, SEEK_CUR );
                                $offset += $blockBytes;
                            }
                            else
                            {
                                if ( $printInfo )
                                    print( ">> GIF image blocks terminated by 0 image block\n" );
                                $dataBlockDone = true;
                            }
                        }
                    }
                    else if ( $blockType == 0x3b ) // Trailer, end of stream
                    {
                        if ( $printInfo )
                            print( "GIF stream terminated by Trailer block\n" );
                        $done = true;
                    }
                    if ( feof( $fd ) )
                        $done = true;
                }
            }
            else
            {
                if ( $printInfo )
                    print( "Not GIF\n" );
                eZDebug::writeError( "The image file $filename is not a GIF file, cannot analyze it", __METHOD__ );
            }
            fclose( $fd );
            $info['is_animated'] = $info['frame_count'] > 1;
            return $info;
        }
        return false;
    }
279547
protected function doUploadMultiple($form_name = 'img', $data = [])
    {
        $this->imageFiles = UploadedFile::getInstancesByName($form_name);
        $quality = self::getQualitySetting(50, $data);
        if ($this->imageFiles) {
            $url = [];
            foreach ($this->imageFiles as $file) {
                $model = new UploadImgForm();
                $model->imageFile = $file;
                $fileName = date('Y/m/d') . '/' . date('his') . '-' . $model->imageFile->baseName. '.' . $model->imageFile->extension;
                $fileName_save = self::getFileNameSave($fileName);
                $model->imageFile->saveAs($fileName_save);
                Image::getImagine()->open($fileName_save)->save($fileName_save, ['quality' => $quality]);
                self::generateThumbnail($fileName, $data);
                $url[] = 'uploads/' . $fileName;
                self::createNewMedia($fileName, $fileName_save, 'uploads/' . $fileName, $data);
            }
            return $url;
        } else {
            return null;
        }
    }
191657
public function createForm($name, $type = "form", array $data = array(), array $options = array())
    {
        if (empty($name)) {
            $name = static::EMPTY_FORM_NAME;
        }

        return $this->getTheliaFormFactory()->createForm($name, $type, $data, $options);
    }
309287
public function addAttachment($filename, $data, $mime = null)
    {
        Argument::i()
            ->test(1, 'string')
            ->test(2, 'string')
            ->test(3, 'string', 'null');

        $this->attachments[] = array($filename, $data, $mime);
        return $this;
    }