Stores the media data at the given file name.

@param string $filename Name of the file to save the media data into
@param string $mimetype Mime type to save the image as
@throws MW_Media_Exception If image couldn't be saved to the given file name
192305
public function save( $filename, $mimetype )
	{
		switch( $mimetype )
		{
			case 'image/gif':

				if( @imagegif( $this->_image, $filename ) === false ) {
					throw new MW_Media_Exception( sprintf( 'Unable to save image to file "%1$s"', $filename ) );
				}

				break;

			case 'image/jpeg':

				$quality = 75;
				if( isset( $this->_options['image']['jpeg']['quality'] ) ) {
					$quality = (int) $this->_options['image']['jpeg']['quality'];
				}

				if( @imagejpeg( $this->_image, $filename, $quality ) === false ) {
					throw new MW_Media_Exception( sprintf( 'Unable to save image to file "%1$s"', $filename ) );
				}

				break;

			case 'image/png':

				$quality = 9;
				if( isset( $this->_options['image']['png']['quality'] ) ) {
					$quality = (int) $this->_options['image']['png']['quality'];
				}

				if( @imagepng( $this->_image, $filename, $quality ) === false ) {
					throw new MW_Media_Exception( sprintf( 'Unable to save image to file "%1$s"', $filename ) );
				}

				break;

			default:
				throw new MW_Media_Exception( sprintf( 'File format "%1$s" is not supported', $this->getMimeType() ) );
		}
	}
448913
public function uploadFiles(string $filename, string $mimetype = '', string $postname = '') {

        $this->params = array_merge($this->params, $this->file($filename, $mimetype, $postname));

        return $this->header(['Content-Type' => 'multipart/form-data']);

    }
551066
public function addAttachmentFromData($name, $data, $mimeType = 'application/octet-stream', $contentId = null)
    {
        $this->_attachments[] = array(
            'name' => $name,
            'mimeType' => $mimeType,
            'data' => $data,
            'contentId' => $contentId
        );
    }
345054
public function isMimeType($filename, $mimeType)
    {
        if (is_array($filename)) {
            $result = array();
            foreach ($filename as $key => $value) {
                $result[] = ($this->getMimeType($value) == (is_array($mimeType) ? $mimeType[$key] : $mimeType))
                            ? true
                            : false;
            }
            return $result;
        } else {
            return $this->getMimeType($filename) == $mimeType ? true : false;
        }
    }
573392
public static function get_type_from_mime_type($mimeType) {
        $types = [
            'image/jpeg' => 'jpg',
            'image/png' => 'png',
            'image/gif' => 'gif',
        ];
        if (isset($types[$mimeType])) return $types[$mimeType];
        throw new ImageException(sprintf('Unsupported MIME type: %s', $mimeType), ImageException::UNSUPPORTED_MIME_TYPE);
    }
283149
public function setMimeType( $mimetype )
	{
		if ( $mimetype == $this->getMimeType() ) { return; }

		if( preg_match( '/^[a-z\-]+\/[a-zA-Z0-9\.\-\+]+$/', $mimetype ) !== 1 ) {
			throw new MShop_Media_Exception( sprintf( 'Invalid mime type "%1$s"', $mimetype ) );
		}

		$this->_values['mimetype'] = (string) $mimetype;
		$this->setModified();
	}
878052
public Entry updateMediaEntry(final String fileName, final String contentType, final InputStream is) throws Exception {
        synchronized (FileStore.getFileStore()) {

            final File tempFile = File.createTempFile(fileName, "tmp");
            final FileOutputStream fos = new FileOutputStream(tempFile);
            Utilities.copyInputToOutput(is, fos);
            fos.close();

            // Update media file
            final FileInputStream fis = new FileInputStream(tempFile);
            saveMediaFile(fileName, contentType, tempFile.length(), fis);
            fis.close();
            final File resourceFile = new File(getEntryMediaPath(fileName));

            // Load media-link entry to return
            final String entryPath = getEntryPath(fileName);
            final InputStream in = FileStore.getFileStore().getFileInputStream(entryPath);
            final Entry atomEntry = loadAtomResourceEntry(in, resourceFile);

            updateTimestamps(atomEntry);
            updateMediaEntryAppLinks(atomEntry, fileName, false);

            // Update feed with new entry
            final Feed f = getFeedDocument();
            updateFeedDocumentWithExistingEntry(f, atomEntry);

            // Save updated media-link entry
            final OutputStream os = FileStore.getFileStore().getFileOutputStream(entryPath);
            updateMediaEntryAppLinks(atomEntry, fileName, true);
            Atom10Generator.serializeEntry(atomEntry, new OutputStreamWriter(os, "UTF-8"));
            os.flush();
            os.close();

            return atomEntry;
        }
    }
727936
public function sendPayload(array $data, $mimeType = null)
    {
        $mimeType = isset($mimeType) ? $mimeType : 'application/json';
        $this->setContentType($mimeType);

        if ($mimeType === 'application/json') {
            $payload = json_encode($data, JSON_PRETTY_PRINT);
        } elseif ($mimeType === 'application/xml') {
            $xml = new \SimpleXMLElement('<?xml version="1.0"?><payload></payload>');
            $this->arrayToXml($data, $xml);
            $payload = $xml->asXML();
        }

        $this->sendHeaders();
        echo $payload;
    }
307872
public function add(string $content, string $mimeType = null, $encoding = null): void
    {
        $contentPart = $this->make();
        $contentPart->content = $content;
        if ($mimeType !== null) {
            $contentPart->mimeType = $mimeType;
        }
        if ($encoding !== null) {
            $contentPart->encoding = $encoding;
        }
        $this->set($contentPart);
    }
1192088
protected function updateFile(FileInterface $file, $resource, $mimetype = NULL) {
    $uri = $file->getFileUri();

    $destination = fopen($uri, 'wb');
    if (!$destination) {
      throw new HttpException(500, "File $uri could not be opened to write.");
    }

    $content_length = stream_copy_to_stream($resource, $destination);

    fclose($destination);

    if ($content_length === FALSE) {
      throw new HttpException(500, "Request body could not be copied to $uri");
    }

    if ($content_length === 0) {
      // Clean up the newly created, empty file.
      unlink($uri);
      throw new HttpException(400, "No bytes were copied to $uri");
    }

    if (!empty($mimetype)) {
      $file->setMimeType($mimetype);
    }

    // Flush the image cache for the image so thumbnails get regenerated.
    image_path_flush($uri);
  }
521627
final public function curlFileCreate(
		$filename,
		$mimetype = null,
		$postname = null
	)
	{
		$file = new \CURLFile($fname, $mime, $name);
		return [$file->getPostFilename(), $file];
	}
523713
public function write($path, $string, $mimeType = null)
    {
        return $this->getFile($path)->write($string, $mimeType);
    }
969891
public function setFilename($filename)
    {
        $this->throwExceptionIfProtected();

        $pathInfo = UnicodeFunctions::pathinfo($filename);
        $extension = (isset($pathInfo['extension']) ? '.' . strtolower($pathInfo['extension']) : '');
        $this->filename = $pathInfo['filename'] . $extension;
        $this->mediaType = Utility\MediaTypes::getMediaTypeFromFilename($this->filename);
    }
111571
public function setContentType($mimeType, $charset = null)
    {
        static $mimes = [];

        if (empty($mimes)) {
            $mimes = require(str_replace('Http', 'Config', __DIR__) . DIRECTORY_SEPARATOR . 'Mimes.php');
        }

        if (strpos($mimeType, '/') === false) {
            $extension = ltrim($mimeType, '.');
            // Is this extension supported?
            if (isset($mimes[ $extension ])) {
                $mimeType =& $mimes[ $extension ];
                if (is_array($mimeType)) {
                    $mimeType = current($mimeType);
                }
            }
        }

        $this->mimeType = $mimeType;

        $this->addHeader(
            'Content-Type',
            $mimeType
            . (empty($charset) ? '' : '; charset=' . $charset)
        );

        return $this;
    }
311303
protected function _getMimeIcon( $mimetype )
	{
		$config = $this->_getContext()->getConfig();

		/** controller/extjs/media/default/mimeicon/directory
		 * Directory that contains the icons for the different mime types
		 *
		 * If no preview image can be generated from an uploaded file, an icon
		 * for its mime type is displayed instead. The directory for the mime
		 * icons is structured by the general mime type (e.g. "image") as
		 * sub-directory and the specific name of the mime type (e.g. "jpeg")
		 * as file name.
		 *
		 * The mime icon directory must be relative to the "basedir" configuration
		 * option. If
		 *
		 *  /var/www/test
		 *
		 * is the configured base directory and the upload directory should be
		 * located in
		 *
		 *  /var/www/test/media/mime
		 *
		 * then the configuration for the uploads directory must be
		 *
		 *  media/mime
		 *
		 * Avoid leading and trailing slashes for the upload directory string!
		 *
		 * @param string Path relative to the base directory
		 * @since 2014.03
		 * @category Developer
		 * @see controller/extjs/media/default/basedir
		 */
		if( ( $mimedir = $config->get( 'controller/extjs/media/default/mimeicon/directory', null ) ) === null )
		{
			$this->_getContext()->getLogger()->log( 'No directory for mime type images configured' );
			return '';
		}

		/** controller/extjs/media/default/mimeicon/extension
		 * File extension of the mime icon images
		 *
		 * If you would like to use different mime icons that are available in
		 * another file format, you have to change the file extension for the
		 * mime icons to the actual ones.
		 *
		 * Note: The configured file extension needs a leading dot!
		 *
		 * @param string File extension including a leading dot, e.g ".jpg"
		 * @since 2014.03
		 * @category Developer
		 */
		$ext = $config->get( 'controller/extjs/media/default/mimeicon/extension', '.png' );
		$abspath = $this->_getAbsoluteDirectory( $mimedir ) . DIRECTORY_SEPARATOR . $mimetype . $ext;
		$mimeicon = $mimedir . DIRECTORY_SEPARATOR . $mimetype . $ext;

		if( is_file( $abspath ) === false ) {
			$mimeicon = $mimedir . DIRECTORY_SEPARATOR . 'unknown' . $ext;
		}

		return $mimeicon;
	}
914100
public function export($path = NULL, $mimetype = NULL) {
		
		if(!$mimetype) {
			$mimetype = $this->mimeType;
		}

		if(!preg_match('#^image/(?:'.implode('|', $this->supportedFormats).')$#', $mimetype)) {
			throw new ImageModifierException("$mimetype not supported by export.");
		}
		
		$this->path = $path ? $path : $this->file;

		// if image was not altered, create only copy
		
		if($this->mimeType == $mimetype && !count($this->queue)) {
			copy($this->file, $this->path);
		}
		
		else {

			foreach($this->queue as $step) {
				call_user_func_array(array($this, 'do_' . $step->method), array_merge(array($this->src), $step->parameters));
			}

			switch($mimetype) {
		
				case 'image/jpeg':
					$this->src->resource->setFormat('jpeg');
					$this->src->resource->setImageCompression(\Imagick::COMPRESSION_JPEG);
					$this->src->resource->setImageCompressionQuality(90);
					break;

				case 'image/png':
					$this->src->resource->setFormat('png');
					$this->src->resource->setImageCompression(\Imagick::COMPRESSION_UNDEFINED);
					$this->src->resource->setImageCompressionQuality(0);
					break;

				case 'image/gif':
					$this->src->resource->setFormat('gif');
					break;
			}
			
			$this->src->resource->writeImage($path);
		}
		
	}
445944
public function getMediaType($mimetype)
    {
        foreach ($this->mediaTypes as $type => $mimeTypes)
        {
            if (in_array($mimetype, $mimeTypes))
            {
                return $type;
            }
        }

        return null;
    }