title: File upload form for custom Joomla component
body: <p>I have a field in my form which is of type file. When the user clicks on the save icon, I want to naturally upload the file to the server and save the filename in the database. I tried testing this out by echoing the filename but it doesn't seem to be working. Also, how do I add the filename to the database? Is it done in the model? Thanks!</p>
  
  <p>controllers/customcom.php</p>
  
  <pre><code>jimport('joomla.filesystem.file');     
  class CustomComControllerCustomCom extends JControllerForm
          {
              function save()
              {
                  $file = JRequest::getVar('img_url', null, 'files', 'array');
  
                  $filename = JFile::makeSafe($file['name']);
  
                  echo $filename;
                  }
          }
  </code></pre>
  
  <p>models/forms/customcom.xml</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
      &lt;form enctype="multipart/form-data"&gt;
              &lt;fieldset&gt;
                    &lt;field
                          name="img_url"
                          type="file"
                          label="Image upload"
                          description=""
                          size="40"
                          class="inputbox"
                          default=""
                  /&gt;
              &lt;/fieldset&gt;
     &lt;/form&gt;
  </code></pre>