user1876234
user1876234

Reputation: 857

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/*" />

Upvotes: 1

Views: 2366

Answers (1)

Bakual
Bakual

Reputation: 2731

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:

  • error
  • name
  • size
  • tmp_name
  • type

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.

Upvotes: 3

Related Questions