src/storage/BaseFileSystemStorage.php
public function addFile($fileSource, $fileName, $folderId = 0, $isHidden = false)
    {
        $fileData = $this->ensureFileUpload($fileSource, $fileName);

        $fileHash = FileHelper::md5sum($fileSource);

        $newName = implode([$fileData['secureFileName'].'_'.$fileData['hashName'], $fileData['extension']], '.');

        if (!$this->fileSystemSaveFile($fileSource, $newName)) {
            return false;
        }

        $model = new StorageFile();
        $model->setAttributes([
            'name_original' => $fileName,
            'name_new' => $fileData['secureFileName'],
            'name_new_compound' => $newName,
            'mime_type' => $fileData['mimeType'],
            'extension' => $fileData['extension'],
            'folder_id' => (int) $folderId,
            'hash_file' => $fileHash,
            'hash_name' => $fileData['hashName'],
            'is_hidden' => $isHidden ? true : false,
            'is_deleted' => false,
            'file_size' => $fileData['fileSize'],
            'caption' => null,
        ]);

        if ($model->validate()) {
            if ($model->save()) {
                $this->deleteHasCache(self::CACHE_KEY_FILE);
                $this->_filesArray[$model->id] = $model->toArray();
                return $this->getFile($model->id);
            }
        }
        return false;
    }
public function addFile($fileSource, $fileName, $folderId = 0, $isHidden = false)
    {
        $fileData = $this->ensureFileUpload($fileSource, $fileName);

        $fileHash = FileHelper::md5sum($fileSource);

        $newName = implode([$fileData['secureFileName'].'_'.$fileData['hashName'], $fileData['extension']], '.');

        if (!$this->fileSystemSaveFile($fileSource, $newName)) {
            return false;
        }

        $model = new StorageFile();
        $model->setAttributes([
            'name_original' => $fileName,
            'name_new' => $fileData['secureFileName'],
            'name_new_compound' => $newName,
            'mime_type' => $fileData['mimeType'],
            'extension' => $fileData['extension'],
            'folder_id' => (int) $folderId,
            'hash_file' => $fileHash,
            'hash_name' => $fileData['hashName'],
            'is_hidden' => $isHidden ? true : false,
            'is_deleted' => false,
            'file_size' => $fileData['fileSize'],
            'caption' => null,
        ]);

        if ($model->validate()) {
            if ($model->save()) {
                $this->deleteHasCache(self::CACHE_KEY_FILE);
                $this->_filesArray[$model->id] = $model->toArray();
                return $this->getFile($model->id);
            }
        }
        return false;
    }
public function addFile ( $ fileSource , $ fileName , $ folderId = 0 , $ isHidden = false ) { $ fileData = $ this -> ensureFileUpload ( $ fileSource , $ fileName ) ; $ fileHash = FileHelper :: md5sum ( $ fileSource ) ; $ newName = implode ( [ $ fileData [ 'secureFileName' ] . '_' . $ fileData [ 'hashName' ] , $ fileData [ 'extension' ] ] , '.' ) ; if ( ! $ this -> fileSystemSaveFile ( $ fileSource , $ newName ) ) { return false ; } $ model = new StorageFile ( ) ; $ model -> setAttributes ( [ 'name_original' => $ fileName , 'name_new' => $ fileData [ 'secureFileName' ] , 'name_new_compound' => $ newName , 'mime_type' => $ fileData [ 'mimeType' ] , 'extension' => $ fileData [ 'extension' ] , 'folder_id' => ( int ) $ folderId , 'hash_file' => $ fileHash , 'hash_name' => $ fileData [ 'hashName' ] , 'is_hidden' => $ isHidden ? true : false , 'is_deleted' => false , 'file_size' => $ fileData [ 'fileSize' ] , 'caption' => null , ] ) ; if ( $ model -> validate ( ) ) { if ( $ model -> save ( ) ) { $ this -> deleteHasCache ( self :: CACHE_KEY_FILE ) ; $ this -> _filesArray [ $ model -> id ] = $ model -> toArray ( ) ; return $ this -> getFile ( $ model -> id ) ; } } return false ; }
Add a new file based on the source to the storage system.

When using the $_FILES array you can also make usage of the file helper methods:

+ {{luya\admin\helpers\Storage::uploadFromFiles}}
+ {{luya\admin\helpers\Storage::uploadFromFileArray}}

When not using the $_FILES array:

```php
Yii::$app->storage->addFile('/the/path/to/File.jpg', 'File.jpg', 0, 1);
```

@param string $fileSource Path to the file source where the file should be created from
@param string $fileName The name of this file (must contain data type suffix).
@param integer $folderId The id of the folder where the file should be stored in.
@param boolean $isHidden Should the file visible in the filemanager or not.
@return bool|\luya\admin\file\Item|Exception Returns the item object, if an error happens an exception is thrown.
@throws Exception
Add a new file based on the source to the storage system .