Results 1 to 6 of 6

Thread: file name from the upload form field

  1. #1
    User
    Join Date
    01-25-10.
    Location
    France
    Posts
    61

    Default file name from the upload form field

    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
    Sharing and growing

  2. #2
    Experienced user
    Join Date
    01-12-10.
    Posts
    814

    Default Re: file name from the upload form field

    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.
    Code:
    // config.php
    $GLOBALS['TL_HOOKS']['loadFormField'][] = array('MyClass', 'myLoadFormField');
     
    // MyClass.php
    public function myLoadFormField(Widget $objWidget, $strForm, $arrForm)
    {
        $objWidget->class = 'myclass';
        return $objWidget;
    }
    Edit:
    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.

  3. #3
    User
    Join Date
    01-25-10.
    Location
    France
    Posts
    61

    Default Re: file name from the upload form field

    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
    Sharing and growing

  4. #4
    Experienced user
    Join Date
    06-20-09.
    Posts
    1,311

    Default Re: file name from the upload form field

    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).

  5. #5
    User
    Join Date
    06-19-09.
    Posts
    328

    Default Re: file name from the upload form field

    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;
    
    }
    Consulenza Contao CMS https://www.intco.it

  6. #6
    Experienced user
    Join Date
    01-12-10.
    Posts
    814

    Default Re: file name from the upload form field

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •