【问题标题】:automatically create a folder and copy files on installation安装时自动创建文件夹并复制文件
【发布时间】:2014-04-29 18:13:27
【问题描述】:

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

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

提前感谢您的帮助。

【问题讨论】:

    标签: joomla joomla2.5 joomla-extensions


    【解决方案1】:

    是的,这是可能的。您首先需要将以下代码添加到您的 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);
            }
    
        }
    
    }
    
    ?>
    

    希望对你有帮助

    【讨论】:

    • 感谢您的快速回答。安装时出现此错误 JFolder::create: Path not in open_basedir paths 你能帮帮我吗?谢谢
    • 我写得很快,今晚有时间再测试一下
    • 碰巧你看过这个吗?谢谢
    猜你喜欢
    • 2021-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多