Joomla! Programmierung/Framework/JFolder/copy

Aus Joomla! Dokumentation
Wechseln zu: Navigation, Suche

JFolder/copy Kopiert einen Ordner.

Inhaltsverzeichnis

[Bearbeiten] Syntax

Joomla 1.5 static copy($src, $dest, [$path], [$force])

Joomla 1.6 static copy($src, $dest, [$path], [$force], [$use_streams])
  • @return mixed object JError bei einem Fehler oder boolean True bei Erfolg.
  • @since Joomla 1.5
Parameter Datentyp Beschreibung Standardwert
$src string Der Pfad zum Quellordner.
$dest string Der Pfad zum Zielordner.
[$path] string Pfad der vorangestellt wird. ' '
[$force] string Überschreiben erzwingen. false
Joomla 1.6
[$use_streams]
bool Sollen Streams genutzt werden false

[Bearbeiten] Beispiel

JFolder::copy('quelle', 'ziel', JPATH_COMPONENT, true);

Kopiert den Ordner Folder blue.png quelle in den Ordner Folder blue.png ziel Im Verzeichnis Ihrer Komponente und überschreibt ihn falls er schon vorhanden ist.

[Bearbeiten] Siehe auch

[Bearbeiten] Quellcode

JFolder::copy in Joomla! 2.5.4

Folder blue.png libraries

  • Folder red.png joomla
    • Folder green.png filesystem
      • File php.png folder.php
  1. public static function copy($src, $dest, $path = '', $force = false, $use_streams = false)
  2. {
  3. @set_time_limit(ini_get('max_execution_time'));
  4.  
  5. // Initialise variables.
  6. $FTPOptions = JClientHelper::getCredentials('ftp');
  7.  
  8. if ($path)
  9. {
  10. $src = JPath::clean($path . '/' . $src);
  11. $dest = JPath::clean($path . '/' . $dest);
  12. }
  13.  
  14. // Eliminate trailing directory separators, if any
  15. $src = rtrim($src, DIRECTORY_SEPARATOR);
  16. $dest = rtrim($dest, DIRECTORY_SEPARATOR);
  17.  
  18. if (!self::exists($src))
  19. {
  20. return JError::raiseError(-1, JText::_('JLIB_FILESYSTEM_ERROR_FIND_SOURCE_FOLDER'));
  21. }
  22. if (self::exists($dest) && !$force)
  23. {
  24. return JError::raiseError(-1, JText::_('JLIB_FILESYSTEM_ERROR_FOLDER_EXISTS'));
  25. }
  26.  
  27. // Make sure the destination exists
  28. if (!self::create($dest))
  29. {
  30. return JError::raiseError(-1, JText::_('JLIB_FILESYSTEM_ERROR_FOLDER_CREATE'));
  31. }
  32.  
  33. // If we're using ftp and don't have streams enabled
  34. if ($FTPOptions['enabled'] == 1 && !$use_streams)
  35. {
  36. // Connect the FTP client
  37. jimport('joomla.client.ftp');
  38. $ftp = JFTP::getInstance($FTPOptions['host'], $FTPOptions['port'], null, $FTPOptions['user'], $FTPOptions['pass']);
  39.  
  40. if (!($dh = @opendir($src)))
  41. {
  42. return JError::raiseError(-1, JText::_('JLIB_FILESYSTEM_ERROR_FOLDER_OPEN'));
  43. }
  44. // Walk through the directory copying files and recursing into folders.
  45. while (($file = readdir($dh)) !== false)
  46. {
  47. $sfid = $src . '/' . $file;
  48. $dfid = $dest . '/' . $file;
  49. switch (filetype($sfid))
  50. {
  51. case 'dir':
  52. if ($file != '.' && $file != '..')
  53. {
  54. $ret = self::copy($sfid, $dfid, null, $force);
  55. if ($ret !== true)
  56. {
  57. return $ret;
  58. }
  59. }
  60. break;
  61.  
  62. case 'file':
  63. // Translate path for the FTP account
  64. $dfid = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $dfid), '/');
  65. if (!$ftp->store($sfid, $dfid))
  66. {
  67. return JError::raiseError(-1, JText::_('JLIB_FILESYSTEM_ERROR_COPY_FAILED'));
  68. }
  69. break;
  70. }
  71. }
  72. }
  73. else
  74. {
  75. if (!($dh = @opendir($src)))
  76. {
  77. return JError::raiseError(-1, JText::_('JLIB_FILESYSTEM_ERROR_FOLDER_OPEN'));
  78. }
  79. // Walk through the directory copying files and recursing into folders.
  80. while (($file = readdir($dh)) !== false)
  81. {
  82. $sfid = $src . '/' . $file;
  83. $dfid = $dest . '/' . $file;
  84. switch (filetype($sfid))
  85. {
  86. case 'dir':
  87. if ($file != '.' && $file != '..')
  88. {
  89. $ret = self::copy($sfid, $dfid, null, $force, $use_streams);
  90. if ($ret !== true)
  91. {
  92. return $ret;
  93. }
  94. }
  95. break;
  96.  
  97. case 'file':
  98. if ($use_streams)
  99. {
  100. $stream = JFactory::getStream();
  101. if (!$stream->copy($sfid, $dfid))
  102. {
  103. return JError::raiseError(-1, JText::_('JLIB_FILESYSTEM_ERROR_COPY_FAILED') . ': ' . $stream->getError());
  104. }
  105. }
  106. else
  107. {
  108. if (!@copy($sfid, $dfid))
  109. {
  110. return JError::raiseError(-1, JText::_('JLIB_FILESYSTEM_ERROR_COPY_FAILED'));
  111. }
  112. }
  113. break;
  114. }
  115. }
  116. }
  117. return true;
  118. }
Meine Werkzeuge
Namensräume
Varianten
Aktionen
Navigation
Sonstiges
Team Navigation
Werkzeuge