Hello,
in loadformfield hook,
I search to know the name of the file which bas been uploaded thanks to a "upload form field", in the front end
Must the tl_log table be parsed ?
Thanks for helping
Printable View
Hello,
in loadformfield hook,
I search to know the name of the file which bas been uploaded thanks to a "upload form field", in the front end
Must the tl_log table be parsed ?
Thanks for helping
Isn't that information supposed to be in the third parameter?
http://www.contao.org/hooks.html#loadFormField:
The loadFormField hook is triggered when a form field is loaded. It passes the widget object, the form ID and the form data as arguments and expects a widget object as return value. It is available from version 2.5.0.
Edit:Code:// config.php
$GLOBALS['TL_HOOKS']['loadFormField'][] = array('MyClass', 'myLoadFormField');
// MyClass.php
public function myLoadFormField(Widget $objWidget, $strForm, $arrForm)
{
$objWidget->class = 'myclass';
return $objWidget;
}
You may be asking for the name of the uploaded file including the path? I'm not sure about that, but a similar question was asked before here: http://www.contao.org/forum/topic/9135.html Though he didn't really solve it in an easy fashion.
Thanks Ruud for replying,
In fact I saw in the contao classes code (FormFileUpload.php) that the file references are deleted (unset($_FILES[$this->strName]).
So , it s not possible to ask the global variable $_FILES after the file upload.
The only place I saw something about the uploaded file, is in the log tl file (the name is written in a log sentence)
But I think that the file name of an uploaded file is important to know inside a piece of code !
Perhaps, a way to solve that is to store values byr the form generator : the file name is writtent in the tl_formadata_detail table ...
but I don't know how parsing the table fields to find the right value (thanks to tstamp field in relation with the tl_formdata table?)!
Thanks for help
Although I completely missed this at the time - I think $file['name'] is the clue if the hook allows access to this (thats what the log entry uses).
You can use a processFormData hook
config.php
-----------------------------
Code:$GLOBALS['TL_HOOKS']['processFormData'][] = array('MyHookClass', 'myProcessFormData');
MyHookClass.php
-----------------------------
Code:public function uploadPackage($arrPost, $arrForm, $arrFiles) {
if ($arrForm['formID'] == '___YOUR_FORM_ID___') {
if (is_array($arrFiles['____your_file_fieldname___'])) {
if (isset($arrFiles['____your_file_fieldname___']['uploaded']) && $arrFiles['____your_file_fieldname___']['uploaded'] == true && $arrFiles['____your_file_fieldname___']['error'] == 0) {
$uploadedFilepath = $arrFiles['____your_file_fieldname___']['tmp_name'];
} else {
$errorCode = $arrFiles['____your_file_fieldname___']['error'];
$this->log('Package upload error', 'uploadPackage', 'UPLOAD_FORM_STD');
// notify error to user
}
}
}
//echo 'a file was uploaded in '.$uploadedFilepath;
}
Is there an apparent reason why access to that information is this restricted? I haven't really looked into this, but I'd like to know in case I need this too.