Actions

API16

Difference between revisions of "JFile/upload"

From Joomla! Documentation

< API16:JFile
(New page: ===Description=== Moves an uploaded file to a destination folder <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton<nowik...)
 
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/upload|Edit Descripton]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
  
{{Description:JFile/upload}}
+
<! removed transcluded page call, red link never existed >
  
 
===Syntax===
 
===Syntax===
Line 98: Line 98:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[SeeAlso:JFile/upload|Edit See Also]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
{{SeeAlso:JFile/upload}}
+
<! removed transcluded page call, red link never existed >
  
 
===Examples===
 
===Examples===
Line 113: Line 113:
 
  format= ,,,
 
  format= ,,,
 
</dpl>
 
</dpl>
 +
[[Category:Archived pages API16]]

Latest revision as of 00:07, 13 May 2013

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

Moves an uploaded file to a destination folder

[<! removed edit link to red link >]

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

Syntax

upload($src, $dest, $use_streams=false)
Parameter Name Default Value Description
$src $src The name of the php (temporary) uploaded file
$dest $dest The path (including filename) to move the uploaded file to
$use_streams false

Returns

boolean True on success

Defined in

libraries/joomla/filesystem/file.php

Importing

jimport( 'joomla.filesystem.file' );

Source Body

function upload($src, $dest, $use_streams=false)
{
 
        // Ensure that the path is valid and clean
        $dest = JPath::clean($dest);
 
        // Create the destination directory if it does not exist
        $baseDir = dirname($dest);
        if (!file_exists($baseDir)) {
                jimport('joomla.filesystem.folder');
                JFolder::create($baseDir);
        }
 
        if($use_streams) {
                $stream =& JFactory::getStream();
                if(!$stream->upload($src, $dest)) {
                        JError::raiseWarning(21, 'JFile::upload: '. $stream->getError());
                        return false;
                }
                return true;
        } else {
                // Initialise variables.
                jimport('joomla.client.helper');
                $FTPOptions = JClientHelper::getCredentials('ftp');
                $ret            = false;
 
        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
                $dest = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $dest), '/');
 
                // Copy the file to the destination directory
                if ($ftp->store($src, $dest)) {
                        $ftp->chmod($dest, 0777);
                        $ret = true;
                } else {
                        JError::raiseWarning(21, JText::_('WARNFS_ERR02'));
                }
        } else {
                if (is_writeable($baseDir) && move_uploaded_file($src, $dest)) { // Short circuit to prevent file permission errors
                        if (JPath::setPermissions($dest)) {
                                $ret = true;
                        } else {
                                JError::raiseWarning(21, JText::_('WARNFS_ERR01'));
                        }
                } else {
                        JError::raiseWarning(21, JText::_('WARNFS_ERR02'));
                }
        }
        return $ret;
}
}

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

Examples

<CodeExamplesForm />