File Upload: Show additional column

File Upload: Show additional column

mp2000mp2000 Posts: 23Questions: 1Answers: 0

Hello,

I want to show the creation date of the uploaded file in the editor, but i only get "undefined | filenameXY.txt"

.

{
    label: "Lizenzdateien:",
    name: "CMDB_Asset_License_File[].id",
    type: "uploadMany",
    display: function(fileId, counter) {
        return '<a href="' + editor.file('CMDB_Asset_License_File', fileId).WebPath + '">' + editor.file('CMDB_Asset_License_File', fileId).DateCreated + ' | ' + editor.file('CMDB_Asset_License_File', fileId).Filename + '</a>';
    },
    noFileText: 'keine Dateien'
},

My sql table has following columns: id | Filename | Filesize | WebPath | SystemPath | DateCreated
the field DateCreated has as standard "CURRENT_TIMESTAMP".
Uploading a file works fine.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,160Questions: 1Answers: 10,406 Site admin

    Do you have the DateCreated field in the db parameters list? Can you show me that PHP or C# code please (I'm not sure which you are using)?

    Allan

  • mp2000mp2000 Posts: 23Questions: 1Answers: 0
    edited November 2017

    Thx for your fast response. I don't know on which position the parameter must be.
    here's my shorten php code:

    Editor::inst($dbIntranet, 'CMDB_Asset')
            ->debug(false)
            ->fields(
                Field::inst('CMDB_Asset.id')->set(false),
                Field::inst('CMDB_Asset_License.id')->set(false),
                Field::inst('CMDB_Asset_License.Note')
            )
            ->leftJoin('CMDB_Asset_License', 'CMDB_Asset_License.cmdb_asset_id', '=', 'CMDB_Asset.id')
            ->join(
                Mjoin::inst('CMDB_Asset_License_File')
                    ->link('CMDB_Asset.id', 'CMDB_Asset_Link_License_File.cmdb_asset_id')
                    ->link('CMDB_Asset_License_File.id', 'CMDB_Asset_Link_License_File.cmdb_asset_license_file_id')
    
                    ->fields(
                        Field::inst('CMDB_Asset_License_File.DateCreated as DateCreated')->set(false),
                        Field::inst('id')
                            ->upload(Upload::inst($_SERVER['DOCUMENT_ROOT'] . '/cxintranet_cms/license/__ID__.__EXTN__')
                                    ->db('CMDB_Asset_License_File', 'id', array(
                                        //date("d.m.Y") . Upload::DB_FILE_NAME
                                        'Filename'   => Upload::DB_FILE_NAME,
                                        'Filesize'   => Upload::DB_FILE_SIZE,
                                        'WebPath'    => Upload::DB_WEB_PATH,
                                        'SystemPath' => Upload::DB_SYSTEM_PATH,
                                    ))
                                    ->validator(function ($file) {
                                        return $file['size'] >= 99999999 ?
                                        "Files must be smaller than 500K" :
                                        null;
                                    })
                                    ->allowedExtensions(array('pdf', 'txt'), "Erlaubt sind .pdf, .txt")
                            )
                    )
            )
            ->process($_POST)
            ->json();
    
  • allanallan Posts: 63,160Questions: 1Answers: 10,406 Site admin
    Answer ✓

    In the db() method you have Filename, Filesize, WebPath and SystemPath, but not the DateCreated field, so it won't be read from the database.

    You should perhaps add:

    'DateCreated' => Upload::DB_READ_ONLY
    

    Allan

  • mp2000mp2000 Posts: 23Questions: 1Answers: 0

    now it works. I didn't know the function yet Upload::DB_READ_ONLY

  • allanallan Posts: 63,160Questions: 1Answers: 10,406 Site admin

    Documentation for all of the options, including DB_READ_ONLY is available here.

    Allan

This discussion has been closed.