在安装时自动创建文件夹并复制文件

时间:2014-04-29 18:13:27

标签: joomla joomla2.5 joomla-extensions

我正在努力解决这个问题。

安装Joomla 2.5插件是否可以自动创建文件夹并将某些文件复制到其中?该文件夹应在图像(joomla默认图像文件夹)/ images /下创建,并在用户安装插件时将一些文件复制到那里。

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

是的,有可能。首先需要将以下代码添加到XML文件中:

<scriptfile>script.php</scriptfile>

然后创建一个名为 script.php 的文件,并将以下代码添加到其中:

<?php

defined('_JEXEC') or die('Restricted access');

class com_helloWorldInstallerScript {

    function install($parent) {

        jimport('joomla.filesystem.folder');
        jimport('joomla.filesystem.file');

        //change this to the name of the folder you want to create
        $newfolder = 'myfolder';

        if(JFolder::create(JUri::root() . 'images/' . $newfolder)) {        
            //duplicate the line below as many times as you want for each file you want to move
            JFile::move(JUri::root() . 'plugins/plugin_name/image.png', JUri::root() . 'images/' . $newfolder);
        }

    }

}

?>

希望这有帮助