Question

My custom component needs a certain path, say /images/example/photos.

How can I create it on installation, but only if it doesn't exist yet?

Was it helpful?

Solution

You will need an install script. To get is set up, have a look at this:

Adding an Install/Uninstall/Update script file

You can remove all the functions but keep the install function. Your final install function should look like this:

function install($parent) {

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

    if(!JFolder::exists(JPATH_ROOT . '/media/images/example/photos')) {
         $path = JPATH_SITE . '/media/images';
         $folder = 'example/photos';
         JFolder::create( $path .'/'. $folder, 0755 );
    }
}

Hope this helps

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top