title: Joomla Custom Component Upload Form
body: <p>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:</p>
  
  <pre><code>protected function getInput()
  {
  
      //Retrieve file details from uploaded file, sent from upload form
      $file = JFactory::getApplication()-&gt;input-&gt;get($this-&gt;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 '&lt;input type="file" name="' . $this-&gt;name . '" id="' . $this-&gt;id . '"' . ' /&gt;';  
  }
  </code></pre>
  
  <p>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: <a href="http://docs.joomla.org/How_to_use_the_filesystem_package" rel="nofollow">http://docs.joomla.org/How_to_use_the_filesystem_package</a> but it neglects to say where the Upload code is supposed to go?</p>
  
  <p>Many thanks</p>