Hi,
I am trying to understand how to allow uploading of files using a developed component.
I created a XML form file for this
<?xml
version="1.0" encoding="utf-8"?>
<form enctype="multipart/form-data">
<fieldset
addruleprefix="Spictera\Component\VolBilling\Administrator\Rule"
addfieldpath="Spictera\Component\VolBilling\Field">
<field
name="customer_id"
type="sql"
query="SELECT id AS value, customer_nm
AS customer_id FROM #__volbilling_customers"
label="COM_VOLBILLING_REPORT_FORM_FIELD_CUSTOMER_NAME_LABEL"
description="COM_VOLBILLING_REPORT_FORM_FIELD_CUSTOMER_NAME_DESC"
required="true"
/>
<field
name="upload_file"
type="file"
label="COM_VOLBILLING_REPORTER_FORM_FIELD_UPLOAD_FILE_NAME_LABEL"
description="COM_VOLBILLING_REPORTER_FORM_FIELD_UPLOAD_FILE_NAME_DESC"
size="40"
class="inputbox"
default=""
/>
</fieldset>
</form>
But only the "customer_id" part is put on screen?
The "upload_file" is never appearing, so it is not even possible to give any input.
Where is this controlled? in the template files?
I use:
<?php echo $this->getForm()->renderField('customer_id'); ?>
But the file data is not in any tables, and should not be?
Do I have to use $_ variables for this? such as:
move_uploaded_file($_FILES[$params->get('efu_variable')]["tmp_name"]
Any one has a complete example of how this can be done in Joomla 4?
Thanks in advance
Hi,
I tried the suggestions, but the array returned is empty?
In the UploadreportController.php:
class
UploadreportController extends FormController
{
public function save($key = null, $urlVar = null)
{
$app = Factory::getApplication();
$file = $app->input->files->get(
'file', null, 'raw');
$files =
$this->input->files->get('data', [], 'array');
$mailer =
Factory::getMailer();
$user =
Factory::getUser();
$recipient =
$user->email;
$mailer->addRecipient($recipient);
$body =
"Hi,\n".var_export($app->input->files,true). ' name:
'.$files . ' tmp: '.$file['tmp_name'];
$mailer->setSubject('debug');
$mailer->setBody($body);
//
$mailer->addAttachment(JPATH_COMPONENT.'/assets/document.pdf');
// send the
email
$send =
$mailer->Send();
return false;
The email I receives has this data:
Hi,
Joomla\CMS\Input\Files::__set_state(array(
'decodedData' =>
array (
),
'inputs' =>
array (
),
'options' =>
array (
),
'filter' =>
Joomla\CMS\Filter\InputFilter::__set_state(array(
'stripUSC' => 0,
'tagsArray' =>
array (
),
'attrArray' =>
array (
),
'tagsMethod' => 0,
'attrMethod' => 0,
'xssAuto' => 1,
'blockedTags' =>
array (
0 => 'applet',
1 => 'body',
2 => 'bgsound',
3 => 'base',
4 => 'basefont',
5 => 'canvas',
6 => 'embed',
7 => 'frame',
8 => 'frameset',
9 => 'head',
10 => 'html',
11 => 'id',
12 => 'iframe',
13 => 'ilayer',
14 => 'layer',
15 => 'link',
16 => 'meta',
17 => 'name',
18 => 'object',
19 => 'script',
20 => 'style',
21 => 'title',
22 => 'xml',
),
'blockedAttributes' =>
array (
0 => 'action',
1 => 'background',
2 => 'codebase',
3 => 'dynsrc',
4 => 'formaction',
5 => 'lowsrc',
),
'blockedChars' =>
array (
0 => '&tab;',
1 => '&space;',
2 => ':',
3 => '&column;',
),
)),
'data' =>
array (
),
)) name: tmp:
This is the form:
<?xml
version="1.0" encoding="utf-8"?>
<form enctype="multipart/form-data">
<fieldset>
<field
name="myfile"
type="file"
label="Arquivo de Aniversariantes"
description="Arquivo na extensão .CSV
com as colunas: NOME, DIA, MES"
size="200"
required="required"
accept="text/comma-separated-values,
text/csv, application/csv, application/excel,
application/vnd.ms-excel, application/vnd.msexcel, text/anytext"
/>
</fieldset>
</form>
How do I get the form data from a file field?
The name of the file, where it is stored,etc?
Regards Tomas
--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/joomla-dev-general/dce4764d-e3c5-44d8-9d74-f3f92c8c3295n%40googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/joomla-dev-general/32e4199a-26fc-2ddb-1a42-9fd67bf78582%40gmail.com.
Hi,
That didn't work either, or I am not doing it rightly.
Dumping does not show the files?object(Joomla\CMS\Input\Files)#1864 (5) {
["decodedData":protected]=>
array(0) {
}
["inputs":protected]=>
array(0) {
}
["options":protected]=>
array(0) {
}
["filter":protected]=>
object(Joomla\CMS\Filter\InputFilter)#166 (9) {
["stripUSC":"Joomla\CMS\Filter\InputFilter":private]=>
int(0)
["tagsArray"]=>
array(0) {
}
["attrArray"]=>
array(0) {
}
["tagsMethod"]=>
int(0)
["attrMethod"]=>
int(0)
["xssAuto"]=>
int(1)
["blockedTags"]=>
array(23) {
[0]=>
string(6) "applet"
[1]=>
string(4) "body"
[2]=>
string(7) "bgsound"
[3]=>
string(4) "base"
[4]=>
string(8) "basefont"
[5]=>
string(6) "canvas"
[6]=>
string(5) "embed"
[7]=>
string(5) "frame"
[8]=>
string(8) "frameset"
[9]=>
string(4) "head"
[10]=>
string(4) "html"
[11]=>
string(2) "id"
[12]=>
string(6) "iframe"
[13]=>
string(6) "ilayer"
[14]=>
string(5) "layer"
[15]=>
string(4) "link"
[16]=>
string(4) "meta"
[17]=>
string(4) "name"
[18]=>
string(6) "object"
[19]=>
string(6) "script"
[20]=>
string(5) "style"
[21]=>
string(5) "title"
[22]=>
string(3) "xml"
}
["blockedAttributes"]=>
array(6) {
[0]=>
string(6) "action"
[1]=>
string(10) "background"
[2]=>
string(8) "codebase"
[3]=>
string(6) "dynsrc"
[4]=>
string(10) "formaction"
[5]=>
string(6) "lowsrc"
}
["blockedChars":"Joomla\Filter\InputFilter":private]=>
array(4) {
[0]=>
string(5) "&tab;"
[1]=>
string(7) "&space;"
[2]=>
string(7) ":"
[3]=>
string(8) "&column;"
}
}
["data":protected]=>
&array(0) {
}
}
But if I dump the $app->input, I can see the sample.csv gets listed, but under other structure.
But still no reference to where the files are located after upload? nor how to deal with the uploaded files?
object(Joomla\CMS\Input\Input)#164 (4) {
["inputs":protected]=>
array(3) {
["server"]=>
object(Joomla\CMS\Input\Input)#172 (4) {
["inputs":protected]=>
array(0) {
}
["options":protected]=>
array(0) {
}
["filter":protected]=>
object(Joomla\Filter\InputFilter)#173 (8) {
["tagsArray"]=>
array(0) {
}
["attrArray"]=>
array(0) {
}
["tagsMethod"]=>
int(0)
["attrMethod"]=>
int(0)
["xssAuto"]=>
int(1)
["blockedTags"]=>
array(23) {
[0]=>
string(6) "applet"
[1]=>
string(4) "body"
[2]=>
...
[22]=>
string(3) "xml"
}
["blockedAttributes"]=>
array(6) {
[0]=>
string(6) "action"
...
[5]=>
string(6) "lowsrc"
}
["blockedChars":"Joomla\Filter\InputFilter":private]=>
array(4) {
[0]=>
...
[3]=>
string(8) "&column;"
}
}
["data":protected]=>
array(55) {
["PHPRC"]=>
string(5) "/etc/"
...
["REQUEST_TIME"]=>
int(1684847484)
}
}
["cookie"]=>
object(Joomla\CMS\Input\Cookie)#197 (4) {
["inputs":protected]=>
array(0) {
}
["options":protected]=>
array(0) {
}
["filter":protected]=>
object(Joomla\CMS\Filter\InputFilter)#166 (9) {
["stripUSC":"Joomla\CMS\Filter\InputFilter":private]=>
int(0)
["tagsArray"]=>
array(0) {
}
["attrArray"]=>
array(0) {
}
["tagsMethod"]=>
int(0)
["attrMethod"]=>
int(0)
["xssAuto"]=>
int(1)
["blockedTags"]=>
array(23) {
[0]=>
string(6) "applet"
..
[22]=>
string(3) "xml"
}
["blockedAttributes"]=>
array(6) {
[0]=>
string(6) "action"
...
[5]=>
string(6) "lowsrc"
}
["blockedChars":"Joomla\Filter\InputFilter":private]=>
array(4) {
[0]=>
string(5) "&tab;"
...
[3]=>
string(8) "&column;"
}
}
["data":protected]=>
&array(3) {
["atumSidebarState"]=>
string(4) "open"
["28491bd904b65c332c8c37b11d0b0226"]=>
string(32) "93d80eebd6fff74a2f6385235a7f65fa"
["3e5a209db69f7a5e45da1150744eefdc"]=>
string(32) "a63ecec1f5eb568841595b1f21b61e2a"
}
}
["files"]=>
object(Joomla\CMS\Input\Files)#1864 (5) {
["decodedData":protected]=>
array(0) {
}
["inputs":protected]=>
array(0) {
}
["options":protected]=>
array(0) {
}
["filter":protected]=>
object(Joomla\CMS\Filter\InputFilter)#166 (9) {
["stripUSC":"Joomla\CMS\Filter\InputFilter":private]=>
int(0)
["tagsArray"]=>
array(0) {
}
["attrArray"]=>
array(0) {
}
["tagsMethod"]=>
int(0)
["attrMethod"]=>
int(0)
["xssAuto"]=>
int(1)
["blockedTags"]=>
array(23) {
[0]=>
string(6) "applet"
[1]=>
...
[22]=>
string(3) "xml"
}
["blockedAttributes"]=>
array(6) {
[0]=>
string(6) "action"
[1]=>
...
[5]=>
string(6) "lowsrc"
}
["blockedChars":"Joomla\Filter\InputFilter":private]=>
array(4) {
[0]=>
string(5) "&tab;"
...
[3]=>
string(8) "&column;"
}
}
["data":protected]=>
&array(0) {
}
}
}
["options":protected]=>
array(0) {
}
["filter":protected]=>
object(Joomla\Filter\InputFilter)#167 (8) {
["tagsArray"]=>
array(0) {
}
["attrArray"]=>
array(0) {
}
["tagsMethod"]=>
int(0)
["attrMethod"]=>
int(0)
["xssAuto"]=>
int(1)
["blockedTags"]=>
array(23) {
[0]=>
string(6) "applet"
[1]=>
...
[22]=>
string(3) "xml"
}
["blockedAttributes"]=>
array(6) {
[0]=>
string(6) "action"
[1]=>
...
[5]=>
string(6) "lowsrc"
}
["blockedChars":"Joomla\Filter\InputFilter":private]=>
array(4) {
[0]=>
string(5) "&tab;"
[1]=>
...
[3]=>
string(8) "&column;"
}
}
["data":protected]=>
array(11) {
["option"]=>
string(14) "com_volbilling"
["layout"]=>
string(4) "edit"
["id"]=>
string(1) "0"
["jform"]=>
array(1) {
["myfile"]=>
string(10) "sample.csv"
}
["task"]=>
string(4) "save"
["da0dad5a4c1f769d13471ab15b28e0e8"]=>
string(1) "1"
["atumSidebarState"]=>
string(4) "open"
["28491bd904b65c332c8c37b11d0b0226"]=>
string(32) "93d80eebd6fff74a2f6385235a7f65fa"
["3e5a209db69f7a5e45da1150744eefdc"]=>
string(32) "a63ecec1f5eb568841595b1f21b61e2a"
["helix_id"]=>
int(9)
["controller"]=>
string(12) "uploadreport"
}
}
To view this discussion on the web, visit https://groups.google.com/d/msgid/joomla-dev-general/CAP5FpwbWnjJJUMG%2BCPORcNfwfG69DKaU0TZC4oYQmiy2KtvryQ%40mail.gmail.com.
Hi again,
If I dump the variables using
var_dump( $app->input->get('jform') );
Than I got the name of the file submitted, but where is the data?
array(1) {
["myfile"]=>
string(10) "sample.csv"
}
To view this discussion on the web, visit https://groups.google.com/d/msgid/joomla-dev-general/CAP5FpwbWnjJJUMG%2BCPORcNfwfG69DKaU0TZC4oYQmiy2KtvryQ%40mail.gmail.com.