Upload the file to the target directory.

@param bool $overwrite
@return bool
@throws \Transit\Exception\ValidationException
978354
public function upload($overwrite = false) {
        $data = $this->_data;

        if (empty($data['tmp_name'])) {
            throw new ValidationException('Invalid file detected for upload');
        }

        // Check upload errors
        if ($data['error'] > 0 || !$this->_isUploadedFile($data['tmp_name'])) {
            switch ($data['error']) {
                case UPLOAD_ERR_INI_SIZE:
                case UPLOAD_ERR_FORM_SIZE:
                    $error = 'File exceeds the maximum file size';
                break;
                case UPLOAD_ERR_PARTIAL:
                    $error = 'File was only partially uploaded';
                break;
                case UPLOAD_ERR_NO_FILE:
                    $error = 'No file was found for upload';
                break;
                default:
                    $error = 'File failed to upload';
                break;
            }

            throw new ValidationException($error);
        }

        // Validate rules
        if ($validator = $this->getValidator()) {
            $validator
                ->setFile(new File($data))
                ->validate();
        }

        // Upload the file
        $target = $this->findDestination($data['name'], $overwrite);

        if ($this->_moveUploadedFile($data['tmp_name'], $target)) {
            $data['name'] = basename($target);
            $data['tmp_name'] = $target;

            $this->_file = new File($data);

            return true;
        }

        throw new ValidationException('An unknown error has occurred');
    }
311792
public static function putContents(string $filename, $data, bool $override = false)
    {
        $dirname = dirname($filename);
        if (!file_exists($dirname)) {
            mkdir($dirname, 0700, true);
        }
        if (!file_exists($filename) || $override) {
            $result = file_put_contents($filename, $data);
        } else {
            throw new \Exception("{$filename} is already exists");
        }
        return $result;
    }
1230408
public function copy(FsPath $fsPath, $filePerm, $overwrite = false) {
		$this->ensureValid();
	
		$this->fileFsPath->copyFile($fsPath, $filePerm, $overwrite);
	}
120106
public function copyFiles($files, $overwrite = null)
	{
		/*
		 * To allow for manual override on the overwriting flag, we check to see if
		 * the $overwrite flag was set and is a boolean value.  If not, use the object
		 * allowOverwrite flag.
		 */

		if (is_null($overwrite) || !is_bool($overwrite))
		{
			$overwrite = $this->overwrite;
		}

		/*
		 * $files must be an array of filenames.  Verify that it is an array with
		 * at least one file to copy.
		 */
		if (is_array($files) && count($files) > 0)
		{

			foreach ($files as $file)
			{
				// Get the source and destination paths
				$filesource = Path::clean($file['src']);
				$filedest = Path::clean($file['dest']);
				$filetype = array_key_exists('type', $file) ? $file['type'] : 'file';

				if (!file_exists($filesource))
				{
					/*
					 * The source file does not exist.  Nothing to copy so set an error
					 * and return false.
					 */
					$this->log(LogLevel::WARNING, Text::sprintf('JLIB_INSTALLER_ERROR_NO_FILE', $filesource));

					return false;
				}
				elseif (($exists = file_exists($filedest)) && !$overwrite)
				{

					// It's okay if the manifest already exists
					if ($this->getPath('manifest') == $filesource)
					{
						continue;
					}

					// The destination file already exists and the overwrite flag is false.
					// Set an error and return false.
					$this->log(LogLevel::WARNING, Text::sprintf('JLIB_INSTALLER_ERROR_FILE_EXISTS', $filedest));

					return false;
				}
				else
				{
					// Copy the folder or file to the new location.
					if ($filetype == 'folder')
					{
						if (!(Folder::copy($filesource, $filedest, null, $overwrite)))
						{
							$this->log(LogLevel::WARNING, Text::sprintf('JLIB_INSTALLER_ERROR_FAIL_COPY_FOLDER', $filesource, $filedest));

							return false;
						}

						$step = array('type' => 'folder', 'path' => $filedest);
					}
					else
					{
						if (!(File::copy($filesource, $filedest, null)))
						{
							$this->log(LogLevel::WARNING, Text::sprintf('JLIB_INSTALLER_ERROR_FAIL_COPY_FILE', $filesource, $filedest));

							// In 3.2, TinyMCE language handling changed.  Display a special notice in case an older language pack is installed.
							if (strpos($filedest, 'media/editors/tinymce/jscripts/tiny_mce/langs'))
							{
								$this->log(LogLevel::WARNING, Text::_('JLIB_INSTALLER_NOT_ERROR'));
							}

							return false;
						}

						$step = array('type' => 'file', 'path' => $filedest);
					}

					/*
					 * Since we copied a file/folder, we want to add it to the installation step stack so that
					 * in case we have to roll back the installation we can remove the files copied.
					 */
					if (!$exists)
					{
						$this->stepStack[] = $step;
					}
				}
			}
		}
		else
		{
			// The $files variable was either not an array or an empty array
			return false;
		}

		return count($files);
	}
806932
public static function createFile($aimUrl, $overWrite = false) {
		if (is_file($aimUrl) && $overWrite == false) {
			return false;
		} elseif (is_file($aimUrl) && $overWrite == true) {
			self::unlinkFile($aimUrl);
		}
		$aimDir = dirname($aimUrl);
		self::createDir($aimDir);
		touch($aimUrl);
		return true;
	}
308703
public static function moveFile($fileUrl, $aimUrl, $overWrite = false) {
		if (!is_file($fileUrl)) {
			return false;
		}
		if (is_file($aimUrl) && $overWrite = false) {
			return false;
		} elseif (is_file($aimUrl) && $overWrite = true) {
			self::unlinkFile($aimUrl);
		}
		$aimDir = dirname($aimUrl);
		self::createDir($aimDir);
		rename($fileUrl, $aimUrl);
		return true;
	}
1178607
public function load($overwrite = false)
	{
		$paths = $this->find_file();

		$lang = array();

		foreach ($paths as $path)
		{
			$lang = $overwrite ?
				array_merge($lang, $this->load_file($path)) :
				\Arr::merge($lang, $this->load_file($path));
		}

		return $lang;
	}
846266
public function copyFile($bucket, $srcFpath, $dstFpath, $overwrite = false)
    {
        $url = self::generateResUrl($bucket, $srcFpath);
        $sign = $this->createNonreusableSignature($bucket, $srcFpath);
        $data = array(
            'op' => 'copy',
            'dest_fileid' => $dstFpath,
            'to_over_write' => $overwrite ? 1 : 0,
        );
        $req = array(
            'url' => $url,
            'method' => 'post',
            'timeout' => self::$timeout,
            'data' => $data,
            'header' => array(
                'Authorization: ' . $sign,
            ),
        );

        return self::sendRequest($req);
    }
70522
public function mergeSupport(Support $support, $overwrite = false)
    {
        $this->support->merge($support, $overwrite);

        return $this;
    }
86147
public static function createZip($destination, $files = [], $blobs = [], $overwrite = true)
    {
        if (!class_exists('ZipArchive')) {
            throw new \Exception('cannot_create_zip_archive');
        }
        //if the zip file already exists and overwrite is false, return false
        if (file_exists($destination) && !$overwrite) {
            return false;
        }
        /* //vars
          $valid_files = array( );
          //if files were passed in...
          if (is_array( $files )) {
          //cycle through each file
          foreach ($files as $file) {
          //make sure the file exists
          if (file_exists( $file )) {
          $valid_files[ ] = $file;
          }
          }
          } */
        //if we have good files...
        // if (count( $valid_files )) {
        //create the archive
        $zip = new ZipArchive();

        if ($zip->open($destination, $overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
            return false;
        }
        //Add the files
        foreach ($files as $file) {
            $filename = $blob['filename'];
            $path = $blob['path'];

            if (!file_exists($path)) {
                throw new \Exception('file_NotFoundException');
            }
            $zip->addFile($filename, $path);
        }
        //Add the $blobs
        foreach ($blobs as $blob) {
            $filename = $blob['filename'];
            $contents = $blob['contents'];
            $zip->addFromString($filename, $contents);
        }

        //debug
        //echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status;
        //close the zip -- done!
        $zip->close();
        //check to make sure the file exists
        return file_exists($destination);
        // } else {
        //     return FALSE;
        //}
    }
884052
public function importFromStream($overwrite = true) {
        $target = $this->findDestination($this->_data, $overwrite);
        $input = fopen('php://input', 'r');
        $output = fopen($target, 'w');

        $size = stream_copy_to_stream($input, $output);

        fclose($input);
        fclose($output);

        if ($size <= 0) {
            @unlink($target);

            throw new IoException('No file detected in input stream');
        }

        $this->_file = new File($target);

        return $size;
    }
1163490
public function decodeFile( $fileName, $overwrite = FALSE )
	{
		if( file_exists( $fileName ) )
		{
			if( $this->isEncoded( $fileName ) )
			{
				$file	= new FS_File_Editor( $fileName );
				$php	= $file->readString();
				$code	= $this->encode( $php );
				$dirname	= dirname( $fileName );
				$basename	= basename( $fileName );
				$target	= $dirname."/".substr( $basename, strlen( $this->filePrefix) , -strlen( $this->fileSuffix ) );
				if( $fileName == $target && !$overwrite )
					throw new RuntimeException( 'File cannot be overwritten, use Parameter "overwrite".' );
				$file->writeString( $code );
				return TRUE;
			}
		}
		return FALSE;	
	}
1344928
public function move($path, $file = null, $overwrite = false)
    {
        if (!$this->isValid()) {
            throw new UploadedFileException('Upload was not successful - '.$this->getErrorMessage());
        }

        $target = $this->getTarget($path, $file);

        if (!$overwrite && is_file($target)) {
            throw new UploadedFileException(sprintf('Could not move the file "%s" to "%s" ( Target file already exists )', $this->getPathname(), $target));
        }

        if (!move_uploaded_file($this->getPathname(), $target)) {
            $error = error_get_last();
            throw new UploadedFileException(sprintf('Could not move the file "%s" to "%s" (%s)', $this->getPathname(), $target, strip_tags($error['message'])));
        }

        chmod($target, 0666 & ~umask());

        return new \SplFileObject($target);
    }
478778
public function add(ContentType $contentType, $overWrite = false)
    {
        if (! $overWrite && $this->has($contentType->getPath())) {
            throw new \Exception('The collection ['.$this->pathLookupTable[$contentType->getPath()].'] already collects for the path ['.$contentType->getPath().']');
        }
        $uid = sha1(md5(get_class($contentType)).'_'.sha1($contentType->getName().'-'.$contentType->getPath()));
        $this->items[$uid] = $contentType;
        $this->pathLookupTable[$contentType->getPath()] = $uid;
        $this->nameLookupTable[$contentType->getName()] = $uid;
    }
1352383
public function encodeFile( $fileName, $overwrite = FALSE )
	{
		if( !file_exists( $fileName ) )
			return FALSE;
		if( $this->isEncoded( $fileName ) )
			return TRUE;
		$php		= FS_File_Reader::load( $fileName );
		$code		= $this->encode( $php );
		$dirname	= dirname( $fileName );
		$basename	= basename( $fileName );
		$target		= $dirname."/".$this->filePrefix.$basename.$this->fileSuffix;
		if( $fileName == $target && !$overwrite )
			throw new RuntimeException( 'File cannot be overwritten, use Parameter "overwrite".' );
//		copy( $fileName, "#".$fileName );
		return (bool) FS_File_Writer::save( $target, $code );
	}
652321
public function send($local_file, $remote_file, $overwrite = false)
    {
        if (false === file_exists($local_file)) {
            return $this->_trigger_error(sprintf('Could not open local file: %s.', $local_file));
        }

        $remote_file = $this->_getAbsoluteRemotePath($remote_file);
        if (false === $overwrite && true === file_exists($remote_file)) {
            return $this->_trigger_error(sprintf('Remote file already exists: %s.', $remote_file));
        }

        if (false === file_exists(dirname($remote_file))) {
            @$this->mkdir(dirname($remote_file), true);
        }

        if (false === @copy($local_file, $remote_file)) {
            return $this->_trigger_error(sprintf('Could not send data from file %s to file %s.', $local_file, $remote_file));
        }

        return true;
    }
123977
public function fileMove($src, $dst, $overwrite = false)
    {
        $src = $this->alias->resolve($src);
        $dst = $this->alias->resolve($dst);

        if (rtrim($dst, '\\/') !== $dst) {
            $dst .= basename($src);
        }

        if (!$overwrite && is_file($dst)) {
            throw new RuntimeException(['move `:src` to `:dst` failed: file exists already', 'src' => $src, 'dst' => $dst]);
        }

        if (!is_dir($dir = dirname($dst))) {
            $this->_dirCreate($dir);
        }

        if (!rename($src, $dst)) {
            throw new RuntimeException(['move `:src` to `:dst` failed: :last_error_message', 'src' => $src, 'dst' => $dst]);
        }
    }