english/libraries/joomla/filesystem/stream.php
/**
	 * File write
	 *
	 * Whilst this function accepts a reference, the underlying fwrite
	 * will do a copy! This will roughly double the memory allocation for
	 * any write you do. Specifying chunked will get around this by only
	 * writing in specific chunk sizes. This defaults to 8192 which is a
	 * sane number to use most of the time (change the default with
	 * JStream::set('chunksize', newsize);)
	 * Note: This doesn't support gzip/bzip2 writing like reading does
	 *
	 * @param   string   $string  Reference to the string to write
	 * @param   integer  $length  Length of the string to write
	 * @param   integer  $chunk  Size of chunks to write in
	 *
	 * @return  boolean
	 *
	 * @see       http://php.net/manual/en/function.fwrite.php
	 * @since   11.1
	 */
File write
Whilst this function accepts a reference, the underlying fwrite
will do a copy. This will roughly double the memory allocation for
any write you do. Specifying chunked will get around this by only
writing in specific chunk sizes. This defaults to 8192 which is a
sane number to use most of the time (change the default with
JStream::set('chunksize', newsize);)
Note: This doesn't support gzip/bzip2 writing like reading does

@param   string   $string  Reference to the string to write
@param   integer  $length  Length of the string to write
@param   integer  $chunk  Size of chunks to write in

@return  boolean


File write Whilst this function accepts a reference the underlying fwrite will do a copy . This will roughly double the memory allocation for any write you do . Specifying chunked will get around this by only writing in specific chunk sizes . This defaults to 8192 which is a sane number to use most of the time ( change the default with JStream :: set ( ' chunksize ' newsize ) ; ) Note : This doesn ' t support gzip / bzip2 writing like reading does @param string $string Reference to the string to write @param integer $length Length of the string to write @param integer $chunk Size of chunks to write in @return boolean
function write(&$string, $length=0, $chunk=0)
	{
		if (!$this->_fh) {
			$this->setError(JText::_('JLIB_FILESYSTEM_ERROR_STREAMS_FILE_NOT_OPEN'));
			return false;
		}
		if (!$length) {
			$length = strlen($string);
		}
		if (!$chunk) {
			$chunk = $this->chunksize;
		}
		$retval = true;
		$php_errormsg = '';
		$track_errors = ini_get('track_errors');
		ini_set('track_errors', true);
		$remaining = $length;
		do
		{
			$amount = ($remaining > $chunk) ? $chunk : $remaining;
			$res = fwrite($this->_fh, $string, $amount);
			if ($res === false) {
				$this->setError($php_errormsg);
				$retval = false;
				$remaining = 0;
			}
			else if ($res === 0) {
								$remaining = 0;
				$this->setError(JText::_('JLIB_FILESYSTEM_ERROR_NO_DATA_WRITTEN'));
			}
			else {
				$remaining -= $res;
			}
		}
		while ($remaining);
		ini_set('track_errors', $track_errors);
		return $retval;
	}
function write ( & $ string , $ length = 0 , $ chunk = 0 ) { if ( ! $ this -> _fh ) { $ this -> setError ( JText :: _ ( 'JLIB_FILESYSTEM_ERROR_STREAMS_FILE_NOT_OPEN' ) ) ; return false ; } if ( ! $ length ) { $ length = strlen ( $ string ) ; } if ( ! $ chunk ) { $ chunk = $ this -> chunksize ; } $ retval = true ; $ php_errormsg = '' ; $ track_errors = ini_get ( 'track_errors' ) ; ini_set ( 'track_errors' , true ) ; $ remaining = $ length ; do { $ amount = ( $ remaining > $ chunk ) ? $ chunk : $ remaining ; $ res = fwrite ( $ this -> _fh , $ string , $ amount ) ; if ( $ res === false ) { $ this -> setError ( $ php_errormsg ) ; $ retval = false ; $ remaining = 0 ; } else if ( $ res === 0 ) { $ remaining = 0 ; $ this -> setError ( JText :: _ ( 'JLIB_FILESYSTEM_ERROR_NO_DATA_WRITTEN' ) ) ; } else { $ remaining -= $ res ; } } while ( $ remaining ) ; ini_set ( 'track_errors' , $ track_errors ) ; return $ retval ; }
File write
 Whilst this function accepts a reference, the underlying fwrite
 will do a copy!
File write Whilst this function accepts a reference the underlying fwrite will do a copy!
// If the length isn't set, set it to the length of the string. // If the chunk isn't set, set it to the default. // Capture PHP errors // If the amount remaining is greater than the chunk size, then use the chunk // Returns false on error or the number of bytes written // Returned error // Wrote nothing?
 // Wrote something // Restore error tracking to what it was before. // Return the result