API15

Difference between revisions of "JFile/write"

From Joomla! Documentation

< API15:JFile
(New page: ===Description=== Write contents to a file <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton<nowiki>]</nowiki> </span> ...)
 
m (removing red link to edit, no existant pages)
Line 3: Line 3:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JFile/write|Edit Descripton]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
  
{{Description:JFile/write}}
+
<! removed transcluded page call, red link never existed >
  
 
===Syntax===
 
===Syntax===
Line 65: Line 65:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[SeeAlso:JFile/write|Edit See Also]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
{{SeeAlso:JFile/write}}
+
<! removed transcluded page call, red link never existed >
  
 
===Examples===
 
===Examples===
Line 80: Line 80:
 
  format= ,,,
 
  format= ,,,
 
</dpl>
 
</dpl>
 +
[[Category:Archived pages API15]]

Revision as of 11:52, 12 May 2013

The "API15" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Write contents to a file

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax[edit]

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

Returns[edit]

boolean True on success

Defined in[edit]

libraries/joomla/filesystem/file.php

Importing[edit]

jimport( 'joomla.filesystem.file' );

Source Body[edit]

function write($file, $buffer)
{
        // Initialize variables
        jimport('joomla.client.helper');
        $FTPOptions = JClientHelper::getCredentials('ftp');

        // 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 ($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;
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples[edit]

<CodeExamplesForm />