开发者

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 h开发者_开发百科ow 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


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.


Uploading any file be it an image on your Joomla site is something which is so simple, and can be done using either the web based FTP and or the desktop FTP services like filezilla but only when you have saved the file you want to upload. Using the web based way, you need to log in to your host for example 000webhost, locate the file manager option, click on it and enter your domain username and password. Then go to public_html folder , create a new folder for your photos or images and click on upload. Locate your image and click on the tick link to start uploading.

Using the desktop way, you will need to unzip your file to add to joomla, open your FTP client like filezilla, locate the file on local host, input your log in details as provided by your host and once you are logged in to your account through filezilla, locate where you want to add the file and click on upload.

You can find a similar tutorial with regard here http://www.thekonsulthub.com/how-tos/how-to-upload-joomla-with-filezilla-to-your-hosting-servers-cpanel/ {entire thing}


Please please please make sure you use the filtering available in the MediaHelper. Specifically never trust uploaded images, always check first that they are valid file types, then that they are in the list of approved types of files listed in your global configuration, that the names do not contain html or javascript, and that the files themselves do not contain code. In particular I would recommend the MediaHelper::canUpload method which will check the majority of these things for you. If anything you should be checking even more strongly. Also make sure that you are checking whether the user has permission to upload. If anything you should make the checking even more restrictive. Use the APIs that joomla gives you, such as the built in media field.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜