Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9075061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:46:55+00:00 2026-06-16T18:46:55+00:00

I’m having trouble creating the upload mechanism for a custom field based on: libraries/joomla/filesystem/file.php.

  • 0

I’m having trouble creating the upload mechanism for a custom field based on: libraries/joomla/filesystem/file.php. The form has the correct enctype set in the view it’s just not uploading. Here’s the code in my component/model/fields/uploadfield.php:

protected function getInput()
{

    //Retrieve file details from uploaded file, sent from upload form
    $file = JFactory::getApplication()->input->get($this->name, null, 'files', 'array');

    //Import filesystem libraries. Perhaps not necessary, but does not hurt
    jimport('joomla.filesystem.file');

    //Clean up filename to get rid of strange characters like spaces etc
    $filename = JFile::makeSafe($file['name']);

    //Set up the source and destination of the file
    $src = $file['tmp_name'];
    $dest = JPATH_COMPONENT . DIRECTORY_SEPARATOR . $filename;

    //First check if the file has the right extension, we need jpg only
    if ( strtolower(JFile::getExt($filename) ) == 'jpg') {
        if ( JFile::upload($src, $dest) ) {
        //Redirect to a page of your choice
        } else {
        //Redirect and throw an error message
        }
    } else {
    //Redirect and notify user file is not right extension
    }

    return '<input type="file" name="' . $this->name . '" id="' . $this->id . '"' . ' />';  
}

Am I even going about this the right way with having the upload mechanism in the getInput() function? Should it be in the model? I’m really stuck with how to make this work, been trying to follow: http://docs.joomla.org/How_to_use_the_filesystem_package but it neglects to say where the Upload code is supposed to go?

Many thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T18:46:56+00:00Added an answer on June 16, 2026 at 6:46 pm

    Ok – so I solved the problem:

    I used the getInput() function in the custom field file to just do the job of displaying the input field on the form and created a function in the controller to do the saving. Goes a little something like this:

    function save(){
        jimport('joomla.filesystem.file');
    
        $jFileInput = new JInput($_FILES);
        $theFiles = $jFileInput->get('jform',array(),'array');
    
        $filepath = "DESTINATIONFILEPATH"
        JFile::upload( $theFiles['tmp_name']['filename'], $filepath );
    
        return parent::save();
    }
    

    Just need to work out the Joomla 3.0 way of saving the filename to the JInput “jform” array so that the filename get’s updated to the database. This just overwrites the existing jform data:

    $jinput = JFactory::getApplication()->input;
    $jinput->set('jform',$arraytoadd);
    

    I’ve asked the question here if anyone is interested:
    Adding field input to JForm using JInput

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.