Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upload a file in joomla?

Hi i am making a simple component in joomla having name image detail and i have to upload that image how can i upload image from backend. which one is better using extension or make custom. can you please share any good article for it. i have searched many more but due to lack of idea on joomla cannot find. hope you genius guys help me.

thanks i advance

like image 580
Pus Avatar asked Oct 11 '22 11:10

Pus


1 Answers

Joomla Component for the exact scenario of your requirement will be very hard to find out. So you've two options: 1. Make your own component 2. Customize other similar type of component like gallery component

For uploading file from joomla component on admin if you're making your own component: 1. Just use move_uploaded_file php function. 2. copy this code, for joomla's standard fxn :

    function upload($src, $dest)
    {
        jimport('joomla.client.helper');
        $FTPOptions = JClientHelper::getCredentials('ftp');
        $ret            = false;
        $dest = JPath::clean($dest);
        $baseDir = dirname($dest);
        if (!file_exists($baseDir)) {
                jimport('joomla.filesystem.folder');
                JFolder::create($baseDir);
        }

        if ($FTPOptions['enabled'] == 1) {
                jimport('joomla.client.ftp');
                $ftp = & JFTP::getInstance($FTPOptions['host'], $FTPOptions['port'], null, $FTPOptions['user'], $FTPOptions['pass']);
                $dest = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $dest), '/');
                if (is_uploaded_file($src) && $ftp->store($src, $dest))
                {
                            $ret = true;
                        unlink($src);
                } else {
                        JError::raiseWarning(21, JText::_('WARNFS_ERR02'));
                }
        } else {
                if (is_writeable($baseDir) && move_uploaded_file($src, $dest)) { // Short circuit to prevent file permission errors
                        if (JPath::setPermissions($dest)) {
                                $ret = true;
                        } else {
                                JError::raiseWarning(21, JText::_('WARNFS_ERR01'));
                        }
                } else {
                        JError::raiseWarning(21, JText::_('WARNFS_ERR02'));
                }
        }
        return $ret;
}

If you want to use other's component and edit it according to need, download it: http://prakashgobhaju.com.np/index.php?option=com_showcase_gallery&view=items&catid=1&Itemid=64 Remember it's a gallery component.

like image 68
Prakash Avatar answered Oct 24 '22 23:10

Prakash