joomlajoomla2.5jform

File upload using JForm


I'm trying to use Joomla's (JForm File Type) form for photo upload. After submiting the form and the file, the field of file remains empty in database. What is missing here ?

My field looks similar to one in jdocs:

<field name="myfilevalue" type="file" label="Enter some text" description="Choose an image from your computer with maximum 100KB" size="10" accept="image/*" />

Solution

  • As far as I know, you need to process the field manually in your models prepareTable function.

    You can access the file using this:

    $jinput = JFactory::getApplication()->input;
    $files  = $jinput->files->get('jform');
    $file   = $files['myfilevalue']
    

    The $file array then holds the following keys:

    You also need to actually move the uploaded file to the final destination. This can be done using JFile::upload().

    Also make sure your form has the enctype="multipart/form-data" set, otherwise it will not work.