public function save(array $attributes = array(), $prefix = self::DEFAULT_FILESTORE_PREFIX) {

		$this->error_code = $this->error;
		$this->error = $this->getError();
		$this->filesize = $this->size;
		$this->path = $this->tmp_name;
		$this->mimetype = $this->detectMimeType();
		$this->simpletype = $this->parseSimpleType();

		if (!$this->isSuccessful()) {
			return $this;
		}

		$prefix = trim($prefix, '/');
		if (!$prefix) {
			$prefix = self::DEFAULT_FILESTORE_PREFIX;
		}

		$id = elgg_strtolower(time() . $this->name);
		$filename = implode('/', array($prefix, $id));

		$type = elgg_extract('type', $attributes, 'object');
		$subtype = elgg_extract('subtype', $attributes, 'file');

		$class = get_subtype_class($type, $subtype);
		if (!$class) {
			$class = '\\ElggFile';
		}

		try {
			$filehandler = new $class();
			foreach ($attributes as $key => $value) {
				$filehandler->$key = $value;
			}
			$filehandler->setFilename($filename);

			$filehandler->title = $this->name;
			$filehandler->originalfilename = $this->name;
			$filehandler->filesize = $this->size;
			$filehandler->mimetype = $this->mimetype;
			$filehandler->simpletype = $this->simpletype;

			$filehandler->open("write");
			$filehandler->close();

			if ($this->simpletype == 'image') {
				$img = new \hypeJunction\Files\Image($this->tmp_name);
				$img->save($filehandler->getFilenameOnFilestore(), hypeApps()->config->getSrcCompressionOpts());
			} else {
				move_uploaded_file($this->tmp_name, $filehandler->getFilenameOnFilestore());
			}

			if ($filehandler->save()) {
				$this->guid = $filehandler->getGUID();
				$this->file = $filehandler;
			}
		} catch (\Exception $ex) {
			elgg_log($ex->getMessage(), 'ERROR');
			$this->error = elgg_echo('upload:error:unknown');
		}

		return $this;
	}
public function save(array $attributes = array(), $prefix = self::DEFAULT_FILESTORE_PREFIX) {

		$this->error_code = $this->error;
		$this->error = $this->getError();
		$this->filesize = $this->size;
		$this->path = $this->tmp_name;
		$this->mimetype = $this->detectMimeType();
		$this->simpletype = $this->parseSimpleType();

		if (!$this->isSuccessful()) {
			return $this;
		}

		$prefix = trim($prefix, '/');
		if (!$prefix) {
			$prefix = self::DEFAULT_FILESTORE_PREFIX;
		}

		$id = elgg_strtolower(time() . $this->name);
		$filename = implode('/', array($prefix, $id));

		$type = elgg_extract('type', $attributes, 'object');
		$subtype = elgg_extract('subtype', $attributes, 'file');

		$class = get_subtype_class($type, $subtype);
		if (!$class) {
			$class = '\\ElggFile';
		}

		try {
			$filehandler = new $class();
			foreach ($attributes as $key => $value) {
				$filehandler->$key = $value;
			}
			$filehandler->setFilename($filename);

			$filehandler->title = $this->name;
			$filehandler->originalfilename = $this->name;
			$filehandler->filesize = $this->size;
			$filehandler->mimetype = $this->mimetype;
			$filehandler->simpletype = $this->simpletype;

			$filehandler->open("write");
			$filehandler->close();

			if ($this->simpletype == 'image') {
				$img = new \hypeJunction\Files\Image($this->tmp_name);
				$img->save($filehandler->getFilenameOnFilestore(), hypeApps()->config->getSrcCompressionOpts());
			} else {
				move_uploaded_file($this->tmp_name, $filehandler->getFilenameOnFilestore());
			}

			if ($filehandler->save()) {
				$this->guid = $filehandler->getGUID();
				$this->file = $filehandler;
			}
		} catch (\Exception $ex) {
			elgg_log($ex->getMessage(), 'ERROR');
			$this->error = elgg_echo('upload:error:unknown');
		}

		return $this;
	}
public function save ( array $ attributes = array ( ) , $ prefix = self :: DEFAULT_FILESTORE_PREFIX ) { $ this -> error_code = $ this -> error ; $ this -> error = $ this -> getError ( ) ; $ this -> filesize = $ this -> size ; $ this -> path = $ this -> tmp_name ; $ this -> mimetype = $ this -> detectMimeType ( ) ; $ this -> simpletype = $ this -> parseSimpleType ( ) ; if ( ! $ this -> isSuccessful ( ) ) { return $ this ; } $ prefix = trim ( $ prefix , '/' ) ; if ( ! $ prefix ) { $ prefix = self :: DEFAULT_FILESTORE_PREFIX ; } $ id = elgg_strtolower ( time ( ) . $ this -> name ) ; $ filename = implode ( '/' , array ( $ prefix , $ id ) ) ; $ type = elgg_extract ( 'type' , $ attributes , 'object' ) ; $ subtype = elgg_extract ( 'subtype' , $ attributes , 'file' ) ; $ class = get_subtype_class ( $ type , $ subtype ) ; if ( ! $ class ) { $ class = '\\ElggFile' ; } try { $ filehandler = new $ class ( ) ; foreach ( $ attributes as $ key => $ value ) { $ filehandler -> $ key = $ value ; } $ filehandler -> setFilename ( $ filename ) ; $ filehandler -> title = $ this -> name ; $ filehandler -> originalfilename = $ this -> name ; $ filehandler -> filesize = $ this -> size ; $ filehandler -> mimetype = $ this -> mimetype ; $ filehandler -> simpletype = $ this -> simpletype ; $ filehandler -> open ( "write" ) ; $ filehandler -> close ( ) ; if ( $ this -> simpletype == 'image' ) { $ img = new \ hypeJunction \ Files \ Image ( $ this -> tmp_name ) ; $ img -> save ( $ filehandler -> getFilenameOnFilestore ( ) , hypeApps ( ) -> config -> getSrcCompressionOpts ( ) ) ; } else { move_uploaded_file ( $ this -> tmp_name , $ filehandler -> getFilenameOnFilestore ( ) ) ; } if ( $ filehandler -> save ( ) ) { $ this -> guid = $ filehandler -> getGUID ( ) ; $ this -> file = $ filehandler ; } } catch ( \ Exception $ ex ) { elgg_log ( $ ex -> getMessage ( ) , 'ERROR' ) ; $ this -> error = elgg_echo ( 'upload:error:unknown' ) ; } return $ this ; }
Saves uploaded file to ElggFile with given attributes

@param array  $attributes New file attributes and metadata
@apara string $prefix     Filestore prefix
@return \Upload
Saves uploaded file to ElggFile with given attributes