Save pre-uploaded file to respective directory.
@param CmgFile $file
@param array $args
168933
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;
	}
715608
public function appendToFile($file, $content)
    {
        if (! file_exists($file)) {
            throw new \Exception('File is missing');
        }
        file_put_contents($file, $content, FILE_APPEND);
    }
962587
public function save(File $file, $filename = null)
    {
        if ($filename !== null) {
            $file->setFilename($filename);
        }

        $this->filesystem->write($file);
    }
1039274
private function saveFile($file, $save)
	{
		$fp = fopen($file, 'w');
		flock($fp, LOCK_EX);
		fwrite($fp, $save);
		flock($fp, LOCK_UN);
		fclose($fp);
		return true;
	}
1267043
protected function save(array $files)
    {
        echo Line::begin('Saving generated files ...', Line::GREEN)->end();

        foreach ($files as $file) {
            $file->save();
        }

        echo Line::begin()->nl();
        echo Line::begin('Copying generated files ...', Line::GREEN)->nl();

        $fileList = $this->buildFileList($this->getTempPath(), $this->basePath);
        $this->copyFiles($fileList);

        echo Line::begin('Removing temporary files ...', Line::GREEN)->nl();

        $this->removeDirectory($this->getTempPath());
    }
65776
public function setDestFile(PhingFile $file)
    {
        $this->cmd->createArgument()->setValue('-o');
        $this->cmd->createArgument()->setFile($file);
    }
1232242
private void addFileToList(final CmsFileInfo file, boolean invalid, boolean existingDeleted, boolean isTooLarge) {

        CmsListInfoBean infoBean = createInfoBean(file);
        CmsListItemWidget listItemWidget = new CmsListItemWidget(infoBean);
        listItemWidget.setIcon(CmsCoreProvider.get().getResourceTypeIcon(file));
        CmsCheckBox check = new CmsCheckBox();
        check.setChecked(false);
        if (!invalid && !isTooLarge && !existingDeleted) {
            if (file.getFileSize() == 0) {
                check.setChecked(false);
            }
            check.setChecked(m_filesToUpload.containsKey(file.getFileName()));
            check.setTitle(file.getFileName());
            if (!m_selectionDone && file.getFileName().toLowerCase().endsWith(".zip")) {
                final Widget unzip = createUnzipCheckBox(file);
                addClickHandlerToCheckBox(check, unzip, file);
                listItemWidget.addButton(unzip);
            } else {
                addClickHandlerToCheckBox(check, null, file);
            }
        } else if (existingDeleted) {
            // is invalid
            String message = Messages.get().key(Messages.GUI_UPLOAD_FILE_EXISTING_DELETED_1, file.getFileName());
            check.disable(message);
            listItemWidget.setBackground(Background.RED);
            listItemWidget.setSubtitleLabel(message);
        } else if (isTooLarge) {
            String message = getFileSizeTooLargeMessage(file);
            check.disable(message);
            listItemWidget.setBackground(Background.RED);
            listItemWidget.setSubtitleLabel(message);
        } else {
            // is invalid
            String message = Messages.get().key(
                Messages.GUI_UPLOAD_FILE_INVALID_NAME_2,
                file.getFileName(),
                CmsUploadButton.formatBytes(file.getFileSize()));
            check.disable(message);
            listItemWidget.setBackground(Background.RED);
            listItemWidget.setSubtitleLabel(message);
        }

        CmsListItem listItem = new CmsListItem(check, listItemWidget);
        m_fileList.addItem(listItem);
        m_listItems.put(file.getFileName(), listItem);
        doResize();
    }
1202977
public function save(File $file, $preparedPath)
    {
        if (false === ($i = array_search($preparedPath, $this->preparedPaths))) {
            throw new \RuntimeException("{$preparedPath} is not prepared by the filemanager");
        }
        unset($this->preparedPaths[$i]);
        $existed = $this->fs->exists($preparedPath);
        @$this->fs->remove($preparedPath);

        try {
            $this->dispatchEvent($existed ? ResourceEvent::REPLACED : ResourceEvent::CREATED, $preparedPath);
            $file->move(dirname($preparedPath), basename($preparedPath));
        } catch (FileException $fileException) {
            throw new FileException(
                $fileException->getMessage() . "\n(hint: check the 'upload_max_filesize' in php.ini)",
                0,
                $fileException
            );
        }
    }
1147063
def upload(file)
      $stderr.puts "Uploading #{file}" if @verbose
      dir = File.dirname(file)
      makedirs(dir)
      @ftp.putbinaryfile(file, file) unless File.directory?(file)
    end
609863
public static function saveAs($file, $options = [])
    {
        if (!($file instanceof UploadedFile)) {
            $file = UploadedFile::getInstanceByName($file);
        }
        $options['file'] = $file;
        $model = new static($options);
        return $model->save() ? $model : false;
    }
772418
protected function mkfile($args) {
		$target = $args['target'];
		$name   = $args['name'];
		
		if (($volume = $this->volume($target)) == false) {
			return array('error' => $this->error(self::ERROR_MKFILE, $name, self::ERROR_TRGDIR_NOT_FOUND, '#'.$target));
		}

		return ($file = $volume->mkfile($target, $args['name'])) == false
			? array('error' => $this->error(self::ERROR_MKFILE, $name, $volume->error()))
			: array('added' => array($file));
	}
792724
function onQuickFormEvent($event, $arg, &$caller)
    {
        switch ($event) {
            case 'updateValue':
                if ($caller->getAttribute('method') == 'get') {
                    return self::raiseError('Cannot add a file upload field to a GET method form');
                }
                $this->_value = $this->_findValue();
                $caller->updateAttributes(array('enctype' => 'multipart/form-data'));
                $caller->setMaxFileSize();
                break;
            case 'addElement':
                $this->onQuickFormEvent('createElement', $arg, $caller);
                return $this->onQuickFormEvent('updateValue', null, $caller);
                break;
            case 'createElement':
                static::__construct($arg[0], $arg[1], $arg[2], $arg[3], $arg[4]);
                break;
        }
        return true;
    }
323214
@CommandArgument
  public void save(
      @OptionArgument("filename") String filename) {

    try {
      PrintStream out = new PrintStream(new FileOutputStream(filename));

      for (User user : users.values()) {
        out.println(user);
      }
    } catch (IOException e) {
      e.printStackTrace();
    }

  }
793896
public function doFilter($file, $arguments, $javaScriptOptions)
    {
        if (! $arguments['minify']) {
            return;
        }

        file_put_contents($file, Minifier::minify(file_get_contents($file)));
    }
1241619
private function _saveBBox($file)
    {
        $this->_saveBBoxRecord($file, 'xmin');
        $this->_saveBBoxRecord($file, 'ymin');
        $this->_saveBBoxRecord($file, 'xmax');
        $this->_saveBBoxRecord($file, 'ymax');
        $this->_saveBBoxRecord($file, 'zmin');
        $this->_saveBBoxRecord($file, 'zmax');
        $this->_saveBBoxRecord($file, 'mmin');
        $this->_saveBBoxRecord($file, 'mmax');
    }
266975
function save ($file = null, $data = array(), $append = false, $fields = array()) {
		if ( empty($file) ) $file = &$this->file;
		$mode = ( $append ) ? 'at' : 'wt' ;
		$is_php = ( preg_match('/\.php$/i', $file) ) ? true : false ;
		return $this->_wfile($file, $this->unparse($data, $fields, $append, $is_php), $mode);
	}
1152358
protected function createLogsFile($file)
    {
        $directory = dirname($file);

        // Create directory
        if (!$this->files->isDirectory($directory)) {
            $this->files->createDir($directory);
        }

        // Create file
        if (!$this->files->has($file)) {
            $this->files->put($file, '');
        }
    }