I would like to know how I upload files to a specific folder through Joomla Administrator Panel (My Component Backend).

I know how to do it in the site part following along with this tutorial:


However I don't know how to do the same thing in the backend part.

I have this in my controller file to edit and add a new image:

protected function allowAdd($data = array())
        return parent::allowAdd($data);

  protected function allowEdit($data = array(), $key = 'id')
        $id = isset( $data[ $key ] ) ? $data[ $key ] : 0;
        if( !empty( $id ) )
            return JFactory::getUser()->authorise( "core.edit", "com_gallery.image." . $id );

I could use my own code inside these functions but I think I won't be able to check if the user has permissions to execute these actions. I'm not sure what JFactory::getUser()->authorise() is for but I think it authorises the user to perform actions when they have permission to do so.

So my question is:

Is there any way to use my own upload code and check whether the user has permissions to execute that action or not?

  • 2
    Not a solution but my advice is not to generate single-use variables. Remove the $id declaration line and just use if (!empty($data[$key])) { ..."com_gallery.image." . $data[$key]); }
    – mickmackusa
    Jul 10 '20 at 14:04
  • 1
    The question isn't very clear. What are you doing in frontend that doesn't work in backend? Why do you need different checks for frontend and backend?
    – Sharky
    Jul 13 '20 at 8:00
  • Actually I'm developing a custom component that allow users to upload images. I would like to upload these images to a cloud storage instead of storing them in default Joomla folder which is media/images (I believe). I can do it easily in frontend but I would like to be able to manage these images from my backend but I don't have as much control as I do in the frontend seeing as in the backend I have that "premade" function to update the images, doing all the job for me. So what would be the best approach to do it? Just put my own code inside the function allowEdit and allowAdd ? Jul 13 '20 at 11:13
  • That's exactly my problem by the way. I don't want different checks haha. I want to be able to upload images to the same place from both frontend and backend. But in the backend I have that allowEdit and allowAdd function that saves the image to the default local Joomla folder. It follows the same sctruture as this tutorial docs.joomla.org/J3.x:Developing_an_MVC_Component/Introduction Jul 13 '20 at 11:20
  • 1
    allowAdd/allowEdit methods shouldn't be uploading anything.
    – Sharky
    Jul 14 '20 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.