JFile/copy

Aus Joomla! Dokumentation
Wechseln zu: Navigation, Suche

JFile/copy Kopiert eine Datei.

Ist der FTP LayerToDo link aktiv, so wird dieser genutzt.

Inhaltsverzeichnis

[Bearbeiten] Syntax

Joomla 1.5
static copy( $src, $dest, [$path] )
Joomla 1.6
static copy( $src, $dest, [$path], [$use_streams] )
  • @return boolean True bei Erfolg
  • @since Joomla 1.5
Parameter Datentyp Beschreibung Standardwert
$src string Der Pfad zur Quelldatei ---
$dest string Der Pfad zur Zieldatei ---
[$path] string Ein Pfad der beiden Pfaden vorangestellt wird null
Joomla 1.6
[$use_streams]
boolean Sollen StreamsToDo link genutzt werden false

[Bearbeiten] Beispiel

[Bearbeiten] Eine Datei kopieren

if( JFile::copy('pfad'.DS.'zur'.DS.'quelle.php', 'pfad'.DS.'zum'.DS.'ziel.php', JPATH_ROOT) )
{
   echo 'Die Datei wurde kopiert';
}

Bei einem Fehler während der Ausführung der Funktion wird eine JError::raiseWarning Fehlermeldung ausgegeben

[Bearbeiten] Siehe auch

[Bearbeiten] Quellcode

JFile::copy in Joomla! 2.5.4

Folder blue.png libraries

  • Folder red.png joomla
    • Folder green.png filesystem
      • File php.png file.php
  1. public static function copy($src, $dest, $path = null, $use_streams = false)
  2. {
  3. // Prepend a base path if it exists
  4. if ($path)
  5. {
  6. $src = JPath::clean($path . '/' . $src);
  7. $dest = JPath::clean($path . '/' . $dest);
  8. }
  9.  
  10. // Check src path
  11. if (!is_readable($src))
  12. {
  13. JError::raiseWarning(21, JText::sprintf('JLIB_FILESYSTEM_ERROR_JFILE_FIND_COPY', $src));
  14.  
  15. return false;
  16. }
  17.  
  18. if ($use_streams)
  19. {
  20. $stream = JFactory::getStream();
  21.  
  22. if (!$stream->copy($src, $dest))
  23. {
  24. JError::raiseWarning(21, JText::sprintf('JLIB_FILESYSTEM_ERROR_JFILE_STREAMS', $src, $dest, $stream->getError()));
  25.  
  26. return false;
  27. }
  28.  
  29. return true;
  30. }
  31. else
  32. {
  33. // Initialise variables.
  34. $FTPOptions = JClientHelper::getCredentials('ftp');
  35.  
  36. if ($FTPOptions['enabled'] == 1)
  37. {
  38. // Connect the FTP client
  39. jimport('joomla.client.ftp');
  40. $ftp = JFTP::getInstance($FTPOptions['host'], $FTPOptions['port'], null, $FTPOptions['user'], $FTPOptions['pass']);
  41.  
  42. // If the parent folder doesn't exist we must create it
  43. if (!file_exists(dirname($dest)))
  44. {
  45. jimport('joomla.filesystem.folder');
  46. JFolder::create(dirname($dest));
  47. }
  48.  
  49. // Translate the destination path for the FTP account
  50. $dest = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $dest), '/');
  51. if (!$ftp->store($src, $dest))
  52. {
  53.  
  54. // FTP connector throws an error
  55. return false;
  56. }
  57. $ret = true;
  58. }
  59. else
  60. {
  61. if (!@ copy($src, $dest))
  62. {
  63. JError::raiseWarning(21, JText::_('JLIB_FILESYSTEM_ERROR_COPY_FAILED'));
  64.  
  65. return false;
  66. }
  67. $ret = true;
  68. }
  69.  
  70. return $ret;
  71. }
  72. }
Meine Werkzeuge
Namensräume
Varianten
Aktionen
Navigation
Sonstiges
Team Navigation
Werkzeuge