Difference between revisions of "JFile/copy"
From Joomla! Documentation
< API15:JFile
(New page: ===Description===
Copies a file
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>Edit Descripton<nowiki>]</nowiki>
</span>
{{Descript...) |
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>[<! removed edit link to red link >]</nowiki> |
</span> | </span> | ||
− | + | <! removed transcluded page call, red link never existed > | |
===Syntax=== | ===Syntax=== | ||
Line 88: | Line 88: | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
− | <nowiki>[< | + | <nowiki>[<! removed edit link to red link >]</nowiki> |
</span> | </span> | ||
− | + | <! removed transcluded page call, red link never existed > | |
===Examples=== | ===Examples=== | ||
Line 103: | Line 103: | ||
format= ,,, | format= ,,, | ||
</dpl> | </dpl> | ||
+ | [[Category:Archived pages API15]] |
Revision as of 11:51, 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]
Copies a file
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax[edit]
copy($src, $dest, $path=null)
Parameter Name | Default Value | Description |
---|---|---|
$src | $src The path to the source file | |
$dest | $dest The path to the destination file | |
$path | null | $path An optional base path to prefix to the file names |
Returns[edit]
boolean True on success
Defined in[edit]
libraries/joomla/filesystem/file.php
Importing[edit]
jimport( 'joomla.filesystem.file' );
Source Body[edit]
function copy($src, $dest, $path = null)
{
// Initialize variables
jimport('joomla.client.helper');
$FTPOptions = JClientHelper::getCredentials('ftp');
// Prepend a base path if it exists
if ($path) {
$src = JPath::clean($path.DS.$src);
$dest = JPath::clean($path.DS.$dest);
}
//Check src path
if (!is_readable($src)) {
JError::raiseWarning(21, 'JFile::copy: ' . JText::_('Cannot find or read file') . ": '$src'");
return 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']);
// If the parent folder doesn't exist we must create it
if (!file_exists(dirname($dest))) {
jimport('joomla.filesystem.folder');
JFolder::create(dirname($dest));
}
//Translate the destination path for the FTP account
$dest = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $dest), '/');
if (!$ftp->store($src, $dest)) {
// FTP connector throws an error
return false;
}
$ret = true;
} else {
if (!@ copy($src, $dest)) {
JError::raiseWarning(21, JText::_('Copy failed'));
return false;
}
$ret = true;
}
return $ret;
}
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples[edit]
<CodeExamplesForm />