common/services/resources/FileService.php
public function saveFile( $file, $args = [] ) {

		// Save only when filename is provided
		if( strlen( $file->name ) > 0 ) {

			$fileManager	= Yii::$app->fileManager;
			$model			= null;
			$attribute		= null;

			// The model and it's attribute used to refer to image
			if( isset( $args[ 'model' ] ) )		$model		= $args[ 'model' ];
			if( isset( $args[ 'attribute' ] ) ) $attribute	= $args[ 'attribute' ];

			// Update File
			$fileId		= $file->id;

			if( $file->changed ) {

				$fileManager->processFile( $file );
			}

			// New File
			if( !isset( $fileId ) || strlen( $fileId ) <= 0 ) {

				// Unset Id
				$file->id = null;

				// Update File Size
				$file->resetSize();

				// Create
				$this->create( $file );

				// Update model attribute
				if( isset( $model ) && isset( $attribute ) ) {

					$model->setAttribute( $attribute, $file->id );
				}
			}
			// Existing File - File Changed
			else if( $file->changed ) {

				// Update File Size
				$file->resetSize();

				$this->updateData( $file );
			}
			// Existing File - Info Changed
			else if( isset( $fileId ) && intval( $fileId ) > 0 ) {

				$this->update( $file );
			}

			$file->changed	= false;
		}

		return $file;
	}
public function saveFile( $file, $args = [] ) {

		// Save only when filename is provided
		if( strlen( $file->name ) > 0 ) {

			$fileManager	= Yii::$app->fileManager;
			$model			= null;
			$attribute		= null;

			// The model and it's attribute used to refer to image
			if( isset( $args[ 'model' ] ) )		$model		= $args[ 'model' ];
			if( isset( $args[ 'attribute' ] ) ) $attribute	= $args[ 'attribute' ];

			// Update File
			$fileId		= $file->id;

			if( $file->changed ) {

				$fileManager->processFile( $file );
			}

			// New File
			if( !isset( $fileId ) || strlen( $fileId ) <= 0 ) {

				// Unset Id
				$file->id = null;

				// Update File Size
				$file->resetSize();

				// Create
				$this->create( $file );

				// Update model attribute
				if( isset( $model ) && isset( $attribute ) ) {

					$model->setAttribute( $attribute, $file->id );
				}
			}
			// Existing File - File Changed
			else if( $file->changed ) {

				// Update File Size
				$file->resetSize();

				$this->updateData( $file );
			}
			// Existing File - Info Changed
			else if( isset( $fileId ) && intval( $fileId ) > 0 ) {

				$this->update( $file );
			}

			$file->changed	= false;
		}

		return $file;
	}
public function saveFile ( $ file , $ args = [ ] ) { // Save only when filename is provided if ( strlen ( $ file -> name ) > 0 ) { $ fileManager = Yii :: $ app -> fileManager ; $ model = null ; $ attribute = null ; // The model and it's attribute used to refer to image if ( isset ( $ args [ 'model' ] ) ) $ model = $ args [ 'model' ] ; if ( isset ( $ args [ 'attribute' ] ) ) $ attribute = $ args [ 'attribute' ] ; // Update File $ fileId = $ file -> id ; if ( $ file -> changed ) { $ fileManager -> processFile ( $ file ) ; } // New File if ( ! isset ( $ fileId ) || strlen ( $ fileId ) <= 0 ) { // Unset Id $ file -> id = null ; // Update File Size $ file -> resetSize ( ) ; // Create $ this -> create ( $ file ) ; // Update model attribute if ( isset ( $ model ) && isset ( $ attribute ) ) { $ model -> setAttribute ( $ attribute , $ file -> id ) ; } } // Existing File - File Changed else if ( $ file -> changed ) { // Update File Size $ file -> resetSize ( ) ; $ this -> updateData ( $ file ) ; } // Existing File - Info Changed else if ( isset ( $ fileId ) && intval ( $ fileId ) > 0 ) { $ this -> update ( $ file ) ; } $ file -> changed = false ; } return $ file ; }
Save pre-uploaded file to respective directory.
@param CmgFile $file
@param array $args
Save pre - uploaded file to respective directory .