Sunday, 15 May 2011

File upload form for custom Joomla component -


I have a form that is of type file when the user clicks on the Save icon, then I naturally I want to upload to the server and save the file name in the database. I tried to test this by echoing the file name but it does not work. Also, how do I add a file name to the database? Is this done in the model? Thanks!

Controller / customcom.php

  Gymport ('joomla.filesystem.file'); Class CustomComControllerCustomCom JControllerForm {function save () {$ file = JRequest :: extends getVar ( 'img_url', null, 'files', 'array'); $ Filename = JFile :: makeSafe ($ file ['name']); $ Filename echo; }}   

Model / Forms / Custom Com Xml

  & 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" square = "input box" default = "" /> & Lt; / Fieldset & gt; & Lt; / Form & gt;    

Just thought it.

The right way

  $ jinput = JFactory :: getApplication () - & gt; Input; $ Files = $ jinput- & gt; File-> Get ('jform'); $ File = $ files ['img_url'];   

This should do the trick

  • Size
  • tmp_name Type

    I removed my original answer because it was misleading.

  • No comments:

    Post a Comment