Actions

API16

Difference between revisions of "JFile/write"

From Joomla! Documentation

< API16:JFile
(New page: ===Description=== Write contents to a file <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton<nowiki>]</nowiki> </span> ...)
 
Line 21: Line 21:
 
|  $file The full file path  
 
|  $file The full file path  
 
|-
 
|-
|  
+
| &$buffer
 
|  
 
|  
 
|  $buffer The buffer to write  
 
|  $buffer The buffer to write  

Revision as of 05:02, 30 March 2010

Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Write contents to a file

[Edit Descripton]

Description:JFile/write

Syntax

write($file, &$buffer, $use_streams=false)
Parameter Name Default Value Description
$file $file The full file path
&$buffer $buffer The buffer to write
$use_streams false

Returns

boolean True on success

Defined in

libraries/joomla/filesystem/file.php

Importing

jimport( 'joomla.filesystem.file' );

Source Body

function write($file, &$buffer, $use_streams=false)
{
 
        // If the destination directory doesn't exist we need to create it
        if (!file_exists(dirname($file))) {
                jimport('joomla.filesystem.folder');
                JFolder::create(dirname($file));
        }
 
        if($use_streams) {
                $stream =& JFactory::getStream();
                $stream->set('chunksize', (1024 * 1024 * 1024)); // beef up the chunk size to a meg
                if(!$stream->writeFile($file, $buffer)) {
                        JError::raiseWarning(21, 'JFile::write('. $file.'): '. $stream->getError());
                        return false;
                }
                return true;
        } else {
                // Initialise variables.
                jimport('joomla.client.helper');
                $FTPOptions = JClientHelper::getCredentials('ftp');
 
        if ($FTPOptions['enabled'] == 1) {
                // Connect the FTP client
                jimport('joomla.client.ftp');
                $ftp = & JFTP::getInstance($FTPOptions['host'], $FTPOptions['port'], null, $FTPOptions['user'], $FTPOptions['pass']);
 
                // Translate path for the FTP account and use FTP write buffer to file
                $file = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $file), '/');
                $ret = $ftp->write($file, $buffer);
        } else {
                $file = JPath::clean($file);
                $ret = file_put_contents($file, $buffer);
        }
        return $ret;
}
}

[Edit See Also] SeeAlso:JFile/write

Examples

<CodeExamplesForm />