Parse Error upload function

Parse Error upload function

Andreas S.Andreas S. Posts: 207Questions: 73Answers: 4

I have problem with the Upload Functions of the Editor. I get this error and I have no idea what I do wrong.

<b>Parse error</b>:  syntax error, unexpected ''i_pdf'' (T_CONSTANT_ENCAPSED_STRING), expecting ')' in <b>C:\xampp7\htdocs\finswimming\assets\lib\evm_server_processing.php</b> on line <b>101</b><br />

I want upload some files (pdf, lxf, zip) and the Information about the files should stored in a extra table, like your example. I have no idea where my fault is.

Andreas

php


if((include 'confic.inc') == FALSE){ echo 'Failed include config'; } if((include PLUGIN_DIR.'DTables/Editor/1.5.6/php/DataTables.php') == FALSE){ echo 'Failed include Edit'; } use DataTables\Editor, DataTables\Editor\Field, DataTables\Editor\Format, DataTables\Editor\Mjoin, DataTables\Editor\Upload, DataTables\Editor\Validate; $db->sql( 'CREATE TABLE IF NOT EXISTS `ltv_events` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT , `federation` VARCHAR(255) NOT NULL, `b_date` DATE NOT NULL , `e_date` DATE NOT NULL , `deadline` DATE NOT NULL , `m_title` VARCHAR(255) NOT NULL , `m_course` VARCHAR(5) NOT NULL , `m_street_1` VARCHAR(255) NOT NULL , `m_street_2` VARCHAR(255) NOT NULL , `m_zip` VARCHAR(10) NOT NULL , `m_city` VARCHAR(255) NOT NULL , `m_nation` VARCHAR(5) NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_unicode_ci;' ); $FormattoSQL = 'd. F Y'; $SQLtoFormat = 'd. F Y'; $store_year = date('Y'); Editor::inst( $db, 'ltv_events', 'id' ) ->fields( Field::inst( 'ltv_events.id' ), Field::inst( 'ltv_events.b_date' ) ->validator( 'Validate::dateFormat', array( 'empty' => false, 'format' => $FormattoSQL )) ->getFormatter( function ($val, $data, $opts ){ if($val === '0000-00-00'){ return NULL; } else{ return date( 'd. F Y', strtotime( $val )); } } ) ->setFormatter( 'Format::date_format_to_sql', $FormattoSQL ), Field::inst( 'ltv_events.e_date' ) ->validator( 'Validate::dateFormat', array( 'empty' => false, 'format' => $FormattoSQL )) ->getFormatter( function ($val, $data, $opts ){ if($val === '0000-00-00'){ return NULL; } else{ return date( 'd. F Y', strtotime( $val )); } } ) ->setFormatter( 'Format::date_format_to_sql', $FormattoSQL ), Field::inst('ltv_events.deadline') ->validator( 'Validate::dateFormat', array( 'format' => $FormattoSQL )) ->getFormatter( function ($val, $data, $opts ){ if($val === '0000-00-00'){ return NULL; } else{ return date( 'd. F Y', strtotime( $val )); } } ) ->setFormatter( 'Format::date_format_to_sql', $FormattoSQL ), Field::inst( 'ltv_events.m_title' ) ->validator( 'Validate::notEmpty') ->validator( 'Validate::minLen', 2 ), Field::inst( 'ltv_events.m_course' )->validator( 'Validate::notEmpty' ), Field::inst( 'ltv_events.m_street_1' ), Field::inst( 'ltv_events.m_street_2' ), Field::inst( 'ltv_events.m_zip' ), Field::inst( 'ltv_events.m_city' ), Field::inst( 'ltv_events.m_nation' ) ->options('nation_codes', 'IOC', 'name_en') ->validator( 'Validate::dbValues' ), Field::inst( 'nation_codes.name_en' ), Field::inst( 'nation_codes.ISO3166-1-Alpha-2 as ISO3166' ), Field::inst( 'ltv_events.federation' ), Field::inst( 'ltv_events.id', 'ltvid') ->getFormatter( function ($val, $data, $opts ){ return 'row_'.$val; }), Field::inst( 'ltv_events_files.i_pdf' ) ->options( 'ltv_events_files', 'id', 'i_pdf') ->validator( 'Validate::dbValues' ) ->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/'.PROJECT_DIR.'/ltv_events/'.$store_year ) ->db( 'ltv_events_files', 'id', array(                 'i_pdf' => Upload::DB_FILE_NAME,                 'i_pdf_file_size' => Upload::DB_FILE_SIZE, 'i_pdf_date' => date('Y-m-d H:i:s') ) ) ->setFormatter( 'Format::nullEmpty' ) ->allowedExtensions( array( 'pdf' ), "Please upload an pdf file") ) ) ->leftJoin('nation_codes', 'nation_codes.IOC', '=', 'ltv_events.m_nation') ->leftJoin('ltv_events_files', 'ltv_events_files.id', '=', 'ltv_events.files') ->process( $_POST ) ->json();

JS:


edit_mlist = new $.fn.dataTable.Editor({ ajax: 'assets/lib/evm_server_processing.php', table: '#meetlist', display: 'bootstrap', fields: [{ label: 'Event Title:', name: 'ltv_events.m_title' },{ type: 'datetime', label: 'Start Date:', name: 'ltv_events.b_date', format: 'DD. MMMM YYYY' },{ type: 'datetime', label: 'End Date:', name: 'ltv_events.e_date', format: 'DD. MMMM YYYY' },{ type: 'datetime', label: 'Deadline:', name: 'ltv_events.deadline', format: 'DD. MMMM YYYY' },{ label: 'Course:', name: 'ltv_events.m_course', type: 'radio', options: [ '50m', '25m'], def: '50m', fieldInfo: '' },{ label: 'Street:', name: 'ltv_events.m_street_1' },{ label: '', name: 'ltv_events.m_street_2' },{ label: 'ZIP:', name: 'ltv_events.m_zip' },{ label: 'City:', name: 'ltv_events.m_city' },{ label: 'Nation:', name: 'ltv_events.m_nation', type: 'select', def: 'AUT' },{ label: 'Invation PDF:', name: 'ltv_events_files.i_pdf', type: 'upload', display: function ( id ) { return editor.file( 'images', id ); } } ] });

Replies

  • allanallan Posts: 61,710Questions: 1Answers: 10,103 Site admin

    Is the PHP you posted evm_server_processing.php? I don't see i_pdf on line 101 and I've just run it through the PHP linter and it checks out as valid syntax.

    Allan

  • Andreas S.Andreas S. Posts: 207Questions: 73Answers: 4

    It is the correct file. I removed the file header Information. the error line is 92

    Andreas

  • Andreas S.Andreas S. Posts: 207Questions: 73Answers: 4
    edited September 2016

    I have found some faults in my Programm code. The Parsing error is gone. I get now json data. But the upload are not working. The following error Message I get:

    Andreas

    <b>Warning</b>:  move_uploaded_file(): The second argument to copy() function cannot be a directory in <b>C:\xampp7\htdocs\finswimming\assets\plugins\DTables\Editor\1.5.6\php\Editor\Upload.php</b> on line <b>457</b><br />
    <br />
    <b>Warning</b>:  move_uploaded_file(): Unable to move 'C:\xampp7\tmp\php8A86.tmp' to 'C:/xampp7/htdocs/finswimming/ltv_events/i/2016/' in <b>C:\xampp7\htdocs\finswimming\assets\plugins\DTables\Editor\1.5.6\php\Editor\Upload.php</b> on line <b>457</b><br />
    {"fieldErrors":[{"name":"ltv_events_files.i_pdf","status":"An error occurred while moving the uploaded file."}],"data":[]}
    

    **PHP **new:

    if((include 'confic.inc') == FALSE){ echo 'Failed include config'; }
    if((include PLUGIN_DIR.'DTables/Editor/1.5.6/php/DataTables.php') == FALSE){ echo 'Failed include Edit'; }
    
    use
      DataTables\Editor,
      DataTables\Editor\Field,
      DataTables\Editor\Format,
      DataTables\Editor\Mjoin,
      DataTables\Editor\Upload,
      DataTables\Editor\Validate;
    
    $db->sql( 'CREATE TABLE IF NOT EXISTS `ltv_events` (
        `id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
        `federation` VARCHAR(255) NOT NULL,
        `b_date` DATE NOT NULL ,
        `e_date` DATE NOT NULL ,
        `deadline` DATE NOT NULL ,
        `m_title` VARCHAR(255) NOT NULL ,
        `m_course` VARCHAR(5) NOT NULL ,
        `m_street_1` VARCHAR(255) NOT NULL ,
        `m_street_2` VARCHAR(255) NOT NULL ,
        `m_zip` VARCHAR(10) NOT NULL ,
        `m_city` VARCHAR(255) NOT NULL ,
        `m_nation` VARCHAR(5) NOT NULL ,
        PRIMARY KEY (`id`))
        ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_unicode_ci;' );
    
    $FormattoSQL = 'd. F Y';
    $SQLtoFormat = 'd. F Y';
    
    $store_year = date('Y');
    if(!is_dir($_SERVER['DOCUMENT_ROOT'].'/'.PROJECT_DIR.'ltv_events/')){
        mkdir($_SERVER['DOCUMENT_ROOT'].'/'.PROJECT_DIR.'ltv_events/');
    }else{
        if(!is_dir($_SERVER['DOCUMENT_ROOT'].'/'.PROJECT_DIR.'ltv_events/i/')){
            mkdir($_SERVER['DOCUMENT_ROOT'].'/'.PROJECT_DIR.'ltv_events/i/');
        }else{
            if(!is_dir($_SERVER['DOCUMENT_ROOT'].'/'.PROJECT_DIR.'ltv_events/i/'.$store_year.'/')){
                mkdir($_SERVER['DOCUMENT_ROOT'].'/'.PROJECT_DIR.'ltv_events/i/'.$store_year.'/');
            }else{
                if(!is_dir($_SERVER['DOCUMENT_ROOT'].'/'.PROJECT_DIR.'ltv_events/i/'.$store_year.'/lxf/')){
                    mkdir($_SERVER['DOCUMENT_ROOT'].'/'.PROJECT_DIR.'ltv_events/i/'.$store_year.'/lxf/');
                }
            }
        }
        if(!is_dir($_SERVER['DOCUMENT_ROOT'].'/'.PROJECT_DIR.'ltv_events/r/')){
            mkdir($_SERVER['DOCUMENT_ROOT'].'/'.PROJECT_DIR.'ltv_events/r/');
        }else{
            if(!is_dir($_SERVER['DOCUMENT_ROOT'].'/'.PROJECT_DIR.'ltv_events/r/'.$store_year.'/')){
                mkdir($_SERVER['DOCUMENT_ROOT'].'/'.PROJECT_DIR.'ltv_events/r/'.$store_year.'/');
            }else{
                if(!is_dir($_SERVER['DOCUMENT_ROOT'].'/'.PROJECT_DIR.'ltv_events/r/'.$store_year.'/lxf/')){
                    mkdir($_SERVER['DOCUMENT_ROOT'].'/'.PROJECT_DIR.'ltv_events/r/'.$store_year.'/lxf/');
                }
            }
        }
    }
    
    Editor::inst( $db, 'ltv_events', 'id' )
        ->fields(
                Field::inst( 'ltv_events.id' ),
                Field::inst( 'ltv_events.b_date' )
                    ->validator( 'Validate::dateFormat', array(
                            'empty' => false,
                            'format'  => $FormattoSQL
               ))
               ->getFormatter( function ($val, $data, $opts ){
                        if($val === '0000-00-00'){ return NULL; }
                        else{ return date( 'd. F Y', strtotime( $val )); }
                    }
                     )
               ->setFormatter( 'Format::date_format_to_sql', $FormattoSQL ),
                Field::inst( 'ltv_events.e_date' )
                    ->validator( 'Validate::dateFormat', array(
                            'empty' => false,
                    'format'  => $FormattoSQL
               ))
               ->getFormatter( function ($val, $data, $opts ){
                        if($val === '0000-00-00'){ return NULL; }
                        else{ return date( 'd. F Y', strtotime( $val )); }
                    }
               )
               ->setFormatter( 'Format::date_format_to_sql', $FormattoSQL ),
                Field::inst('ltv_events.deadline')
                    ->validator( 'Validate::dateFormat', array(
                    'format'  => $FormattoSQL
               ))
               ->getFormatter( function ($val, $data, $opts ){
                        if($val === '0000-00-00'){ return NULL; }
                        else{ return date( 'd. F Y', strtotime( $val )); }
                    }
                     )
               ->setFormatter( 'Format::date_format_to_sql', $FormattoSQL ),
                Field::inst( 'ltv_events.m_title' )
                    ->validator( 'Validate::notEmpty')
                    ->validator( 'Validate::minLen', 2 ),
                Field::inst( 'ltv_events.m_course' )->validator( 'Validate::notEmpty' ),
                Field::inst( 'ltv_events.m_street_1' ),
                Field::inst( 'ltv_events.m_street_2' ),
                Field::inst( 'ltv_events.m_zip' ),
                Field::inst( 'ltv_events.m_city' ),
            Field::inst( 'ltv_events.m_nation' )
                ->options('nation_codes', 'IOC', 'name_en')
                ->validator( 'Validate::dbValues' ),
            Field::inst( 'nation_codes.name_en' ),
            Field::inst( 'nation_codes.ISO3166-1-Alpha-2 as ISO3166' ),
                Field::inst( 'ltv_events.federation' ),
                Field::inst( 'ltv_events.id', 'ltvid')
                    ->getFormatter( function ($val, $data, $opts ){
                        return 'row_'.$val;
                    }),
                Field::inst( 'ltv_events_files.i_pdf' )
                    ->options( 'ltv_events_files', 'id', 'i_pdf')
                    ->validator( 'Validate::dbValues' )
                    ->upload(
                        Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/'.PROJECT_DIR.'ltv_events/i/'.$store_year.'/' )
                            ->db( 'ltv_events_files', 'id', array(
                                'i_pdf' => Upload::DB_FILE_NAME,
                                'i_pdf_file_size' => Upload::DB_FILE_SIZE,
                                'i_pdf_date' => date('Y-m-d H:i:s') )
                                )
                            ->allowedExtensions( array( 'pdf' ), 'Please upload an pdf file')
                    )
                    ->setFormatter( 'Format::nullEmpty' )
        )
        ->leftJoin('nation_codes', 'nation_codes.IOC', '=', 'ltv_events.m_nation')
        ->leftJoin('ltv_events_files', 'ltv_events_files.id', '=', 'ltv_events.id')
            ->process( $_POST )
        ->json();
    
  • allanallan Posts: 61,710Questions: 1Answers: 10,103 Site admin

    move_uploaded_file(): The second argument to copy() function cannot be a directory

    Is coming about because you are trying to store all files here:

    $_SERVER['DOCUMENT_ROOT'].'/'.PROJECT_DIR.'ltv_events/i/'.$store_year.'/'

    i.e. as a directory. You need to give it some file information such as one of the auto variables that Editor will replace. See the documentation here.

    Allan

  • Andreas S.Andreas S. Posts: 207Questions: 73Answers: 4

    Sorry for my late answer, but I was on vacation for 3 weeks. I have changed that and the upload works. Did the upload support UTF-8 Chars in the filename? the filename are store as I_ÖJM+ÖBM-Schwimmen_2016.pdf and not as I_ÖJM+ÖBM-Schwimmen_2016.pdf

    Andreas

  • allanallan Posts: 61,710Questions: 1Answers: 10,103 Site admin

    It should do - does the file system you are using support UTF8 characters? To Editor itself I don't think the characters used should make any difference.

    Allan

  • Andreas S.Andreas S. Posts: 207Questions: 73Answers: 4

    I use my development environment XAMPP for windows. Windows supports special Chars in the file Systems. In other Projects I used the move_uploaded_file with special chars and windows stored it correct. Maybe php 7 makes the Problem

  • Andreas S.Andreas S. Posts: 207Questions: 73Answers: 4
    edited October 2016

    I have some Problem to display the filename of the uploaded files in the Modal window. I put the code return edit_mlist.file( 'ltv_events_files', id ); in the display attribute but I get the js error :

    ! SCRIPT438: Object doesn't support property or method 'file' fu_mlist.js (113,6)

    I tried some variation that I read in your documentation, but the browser shows always this error. Next I tried to use my datatable object instead the editor object return meetlist.file( 'ltv_events_files', id );
    The error is gone, but nothing is showing in the modal window. the editor knows, that a information about the filename are in the database, because the delete Button are visible in the modal Window. I'm a little bit frustrated, because I did not find my fault.

    Andreas

  • Andreas S.Andreas S. Posts: 207Questions: 73Answers: 4

    a joke?

  • allanallan Posts: 61,710Questions: 1Answers: 10,103 Site admin

    ! SCRIPT438: Object doesn't support property or method 'file' fu_mlist.js (113,6)

    What is edit_mlist? Is it a DataTable instance or an Editor instance? It should be a DataTables instance (see file()). I have a feeling edit_mlist might be an Editor instance.

    Regards,
    Allan

  • Andreas S.Andreas S. Posts: 207Questions: 73Answers: 4

    meetlist is the datatable and edit_mlist is the editor instance. I tried with the table instance (meetlist), but I did not get the filename in the editor. The table instance should not show the filename. I have not render anything.
    My File Database looks like this.

    MariaDB [9085552db3]> describe ltv_events_files;
    +-----------------+------------------+------+-----+-------------------+-----------------------------+
    | Field           | Type             | Null | Key | Default           | Extra                       |
    +-----------------+------------------+------+-----+-------------------+-----------------------------+
    | id              | int(10) unsigned | NO   | PRI | NULL              | auto_increment              |
    | i_pdf           | varchar(255)     | YES  |     | NULL              |                             |
    | i_pdf_file_size | int(11)          | YES  |     | NULL              |                             |
    | i_pdf_date      | datetime         | YES  |     | NULL              |                             |
    | i_lxf           | varchar(255)     | YES  |     | NULL              |                             |
    | i_lxr_file_size | int(11)          | YES  |     | NULL              |                             |
    | i_lxf_date      | datetime         | YES  |     | NULL              |                             |
    | s_pdf           | varchar(255)     | YES  |     | NULL              |                             |
    | s_pdf_file_size | int(11)          | YES  |     | NULL              |                             |
    | s_pdf_date      | datetime         | YES  |     | NULL              |                             |
    | livetiming_url  | varchar(255)     | YES  |     | NULL              |                             |
    | r_pdf           | varchar(255)     | YES  |     | NULL              |                             |
    | r_pdf_file_size | int(11)          | YES  |     | NULL              |                             |
    | r_pdf_date      | datetime         | YES  |     | NULL              |                             |
    | r_lxf           | varchar(255)     | YES  |     | NULL              |                             |
    | r_lxf_file_size | int(11)          | YES  |     | NULL              |                             |
    | r_lxf_date      | datetime         | YES  |     | NULL              |                             |
    | system_path     | varchar(255)     | YES  |     | NULL              |                             |
    | web_path        | varchar(255)     | YES  |     | NULL              |                             |
    | uploaded        | timestamp        | NO   |     | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
    +-----------------+------------------+------+-----+-------------------+-----------------------------+
    

    I want to show the filename of the pdf that is stored in i_pdf and so on.

    Andeas

  • allanallan Posts: 61,710Questions: 1Answers: 10,103 Site admin

    Can you give me a link to the page so I can debug the live code please.

    Thanks,
    Allan

  • allanallan Posts: 61,710Questions: 1Answers: 10,103 Site admin

    Could you change:

    return edit_mlist.file( 'ltv_events_files', id );

    to be:

    return meetlist.file( 'ltv_events_files', id ).i_pdf;
    

    which I think should address the error.

    Regards,
    Allan

  • Andreas S.Andreas S. Posts: 207Questions: 73Answers: 4

    ok I change it, but the editor show no File.

    Andreas

  • allanallan Posts: 61,710Questions: 1Answers: 10,103 Site admin

    name: 'ltv_events_files.i_pdf'

    I think this is the issue. That should be set to the table/column that you want this field to edit the value of. I might be misunderstand the code, but it looks like the foreign key reference is not in the host table like I would expect, but rather its in the files table.

    Are you able to add another field to the ltv_events table which will reference the id from the ltv_events_files table? That will probably be a bit easier to work with as that's how the examples work.

    Allan

  • Andreas S.Andreas S. Posts: 207Questions: 73Answers: 4

    I'm not sure to understand you right. Should I rename the id of the ltv_events_files Database or add an additional column that reverence to the ltv_events_files Table id?

    Andreas

  • allanallan Posts: 61,710Questions: 1Answers: 10,103 Site admin

    My suggestion would be that your ltv_events table should have a column that references the ltv_events_files.

    I think your model is currently the other way around, which isn't a case for which the Editor server-side code was designed (there might be a way to make it work - but having it this way around appears to be more flexible to me).

    Allan

  • Andreas S.Andreas S. Posts: 207Questions: 73Answers: 4
    edited October 2016

    I have now chanced my database model.

    Database model:

    +------------+------------------+------+-----+-------------------+-----------------------------+
    | Field      | Type             | Null | Key | Default           | Extra                       |
    +------------+------------------+------+-----+-------------------+-----------------------------+
    | id         | int(10) unsigned | NO   | PRI | NULL              | auto_increment              |
    | federation | varchar(255)     | NO   |     | NULL              |                             |
    | b_date     | date             | NO   |     | NULL              |                             |
    | e_date     | date             | NO   |     | NULL              |                             |
    | deadline   | date             | NO   |     | NULL              |                             |
    | m_title    | varchar(255)     | NO   |     | NULL              |                             |
    | m_course   | varchar(5)       | NO   |     | NULL              |                             |
    | m_street_1 | varchar(255)     | NO   |     | NULL              |                             |
    | m_street_2 | varchar(255)     | NO   |     | NULL              |                             |
    | m_zip      | varchar(10)      | NO   |     | NULL              |                             |
    | m_city     | varchar(255)     | NO   |     | NULL              |                             |
    | m_nation   | varchar(5)       | NO   |     | NULL              |                             |
    | fileID     | int(10) unsigned | YES  | UNI | NULL              |                             |
    | updated    | timestamp        | NO   |     | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
    +------------+------------------+------+-----+-------------------+-----------------------------+
    
    MariaDB [fs_db]> describe fs_events_files;
    +-------------------+------------------+------+-----+---------------------+-----------------------------+
    | Field             | Type             | Null | Key | Default             | Extra                       |
    +-------------------+------------------+------+-----+---------------------+-----------------------------+
    | fileID            | int(11) unsigned | NO   | PRI | NULL                | auto_increment              |
    | i_pdf_file_name   | varchar(100)     | YES  |     | NULL                |                             |
    | i_pdf_file_size   | int(11)          | YES  |     | NULL                |                             |
    | i_pdf_date        | datetime         | NO   |     | 0000-00-00 00:00:00 |                             |
    | i_pdf_web_path    | varchar(255)     | YES  |     | NULL                |                             |
    | i_pdf_system_path | varchar(255)     | YES  |     | NULL                |                             |
    | i_pdf_extn        | varchar(5)       | YES  |     | NULL                |                             |
    | i_pdf_mime_type   | varchar(50)      | YES  |     | NULL                |                             |
    | i_lxf_file_name   | varchar(100)     | YES  |     | NULL                |                             |
    | i_lxr_file_size   | int(11)          | YES  |     | NULL                |                             |
    | i_lxf_date        | datetime         | NO   |     | 0000-00-00 00:00:00 |                             |
    | i_lxf_web_path    | varchar(255)     | YES  |     | NULL                |                             |
    | i_lxf_system_path | varchar(255)     | YES  |     | NULL                |                             |
    | i_lxf_extn        | varchar(5)       | YES  |     | NULL                |                             |
    | i_lxf_mime_type   | varchar(50)      | YES  |     | NULL                |                             |
    | s_pdf_file_name   | varchar(100)     | YES  |     | NULL                |                             |
    | s_pdf_file_size   | int(11)          | YES  |     | NULL                |                             |
    | s_pdf_date        | datetime         | NO   |     | 0000-00-00 00:00:00 |                             |
    | s_pdf_web_path    | varchar(255)     | YES  |     | NULL                |                             |
    | s_pdf_system_path | varchar(255)     | YES  |     | NULL                |                             |
    | s_pdf_extn        | varchar(5)       | YES  |     | NULL                |                             |
    | s_pdf_mime_type   | varchar(50)      | YES  |     | NULL                |                             |
    | r_pdf_file_name   | varchar(100)     | YES  |     | NULL                |                             |
    | r_pdf_file_size   | int(11)          | YES  |     | NULL                |                             |
    | r_pdf_date        | datetime         | NO   |     | 0000-00-00 00:00:00 |                             |
    | r_pdf_web_path    | varchar(255)     | YES  |     | NULL                |                             |
    | r_pdf_system_path | varchar(255)     | YES  |     | NULL                |                             |
    | r_pdf_extn        | varchar(5)       | YES  |     | NULL                |                             |
    | r_pdf_mime_type   | varchar(50)      | YES  |     | NULL                |                             |
    | r_lxf_file_name   | varchar(100)     | YES  |     | NULL                |                             |
    | r_lxf_file_size   | int(11)          | YES  |     | NULL                |                             |
    | r_lxf_date        | datetime         | NO   |     | 0000-00-00 00:00:00 |                             |
    | r_lxf_web_path    | varchar(255)     | YES  |     | NULL                |                             |
    | r_lxf_system_path | varchar(255)     | YES  |     | NULL                |                             |
    | r_lxf_extn        | varchar(5)       | YES  |     | NULL                |                             |
    | r_lxf_mime_type   | varchar(50)      | YES  |     | NULL                |                             |
    | livetiming_url    | varchar(255)     | YES  |     | NULL                |                             |
    | uploaded          | timestamp        | NO   |     | CURRENT_TIMESTAMP   | on update CURRENT_TIMESTAMP |
    +-------------------+------------------+------+-----+---------------------+-----------------------------+
    
    
                    }),
                Field::inst( 'fs_events_files.i_pdf_file_name' )
                    ->options( 'fs_events_files', 'fileID', 'i_pdf_file_name')
                    ->validator( 'Validate::dbValues' )
                    ->upload(
                        Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/'.PROJECT_DIR.'ltv_events/i/'.$store_year.'/__NAME__' )
                            ->db( 'fs_events_files', 'fileID', array(
                                'i_pdf_file_name'       => Upload::DB_FILE_NAME,
                                'i_pdf_file_size'       => Upload::DB_FILE_SIZE,
                                'i_pdf_date'                    => date('Y-m-d H:i:s'),
                                'i_pdf_web_path'            => Upload::DB_WEB_PATH,
                                'i_pdf_system_path'     => Upload::DB_SYSTEM_PATH,
                                'i_pdf_mime_type'       => Upload::DB_MIME_TYPE,
                                'i_pdf_extn'                    => Upload::DB_EXTN )
                                )
                            ->allowedExtensions( array( 'pdf' ), 'Only pdf file are allowed!')
                    )
                    ->setFormatter( 'Format::nullEmpty' ),
                Field::inst( 'fs_events_files.i_pdf_date' )
                    ->getFormatter( function ($val, $data, $opts ){
                    if($val === '0000-00-00 00:00:00'){ return ''; }
                    else{ return date( 'd.m.y H:i:s', strtotime( $val )); }
               })
    
    
        )
        ->leftJoin('nation_codes', 'nation_codes.IOC', '=', 'fs_events.m_nation')
        ->leftJoin('fs_events_files', 'fs_events_files.fileID', '=', 'fs_events.fileID')
    
    

    JS:

    $(document).ready(function(){
        $.fn.dataTable.Editor.classes.field.label='label-width';
    
        edit_mlist = new $.fn.dataTable.Editor({
            ajax: 'assets/lib/evm_server_processing.php',
            table: '#meetlist',
            display: 'bootstrap',
            fields: [{
                    label: 'Event Title:',
                name: 'fs_events.m_title'
                },{
                    type: 'datetime',
                    label: 'Start Date:',
                name: 'fs_events.b_date',
                format: 'DD. MMMM YYYY'
                },{
                    type: 'datetime',
                    label: 'End Date:',
                name: 'fs_events.e_date',
                format: 'DD. MMMM YYYY'
                },{
                    type: 'datetime',
                    label: 'Deadline:',
                name: 'fs_events.deadline',
                format: 'DD. MMMM YYYY'
                },{
                    label: 'Course:',
                    name: 'fs_events.m_course',
                    type: 'radio',
                    options: [ '50m', '25m'],
                    def: '50m',
                    fieldInfo: ''
                },{
                    label: 'Street:',
                    name: 'fs_events.m_street_1'
                },{
                    label: '',
                    name: 'fs_events.m_street_2'
                },{
                    label: 'ZIP:',
                    name: 'fs_events.m_zip'
                },{
                    label: 'City:',
                    name: 'fs_events.m_city'
                },{
                    label: 'Nation:',
                    name: 'fs_events.m_nation',
                    type: 'select',
                    def: 'AUT'
                },{
                    label: 'Invitation PDF:',
                    name: 'fs_events_files.i_pdf_file_name',
                    type: 'upload',
                    display: function( fileID ){
                        return meetlist.file( 'fs_events_files', fileID ).i_pdf_file_name;
                    },
                    dragDrop: false,
                    clearText: 'Remove file'
                }
            ]
        });
    

    The upload works fine, but the editor did not show the entries. If you upload the file you see the remove button and the filename. Close the windows and open it again, you see no file and the remove button is not here.

    Andreas

  • allanallan Posts: 61,710Questions: 1Answers: 10,103 Site admin

    The client-side is sending:

    data[row_1][fs_events_files][i_pdf_file_name]:9

    to the server.

    However, I would suggest that you need to write the file ID to the fileID in your main table (ltv_events I think).

    Allan

  • Andreas S.Andreas S. Posts: 207Questions: 73Answers: 4

    the fileID is stored in the Maintable.fileID. I have checked it. but the upload create an new id in the filetable. I have no idea, why the system that do. see the screenshots of the Database.

  • allanallan Posts: 61,710Questions: 1Answers: 10,103 Site admin

    Its sending that parameter because the Editor field definition for the upload field contains:

    name: 'fs_events_files.i_pdf_file_name',

    It should be fs_events.fileID I think, since that is where you want to store the id of the file that is associated with that row.

    Allan

  • Andreas S.Andreas S. Posts: 207Questions: 73Answers: 4

    I change the line, but it did not work. See screenshot of the error

    Andreas

  • allanallan Posts: 61,710Questions: 1Answers: 10,103 Site admin

    Did you update the PHP script to reflect that the upload should be on the fs_events.fileID field?

    Allan

  • Andreas S.Andreas S. Posts: 207Questions: 73Answers: 4

    I update the php to:

                Field::inst( 'fs_events_files.fileID' )
                    ->options( 'fs_events_files', 'fileID', 'i_pdf_file_name')
                    ->validator( 'Validate::dbValues' )
                    ->upload(
                        Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/'.PROJECT_DIR.'ltv_events/i/'.$store_year.'/__NAME__' )
                            ->db( 'fs_events_files', 'fileID', array(
                                'i_pdf_file_name'       => Upload::DB_FILE_NAME,
                                'i_pdf_file_size'       => Upload::DB_FILE_SIZE,
                                'i_pdf_date'                    => date('Y-m-d H:i:s'),
                                'i_pdf_web_path'            => Upload::DB_WEB_PATH,
                                'i_pdf_system_path'     => Upload::DB_SYSTEM_PATH,
                                'i_pdf_mime_type'       => Upload::DB_MIME_TYPE,
                                'i_pdf_extn'                    => Upload::DB_EXTN )
                                )
                            ->allowedExtensions( array( 'pdf' ), 'Only pdf file are allowed!')
                    )
                    ->setFormatter( 'Format::nullEmpty' ),
    
    

    and the js script to

                    label: 'Invitation PDF:',
                    name: 'fs_events_files.fileID',
                    type: 'upload',
                    display: function( fileID ){
                        return meetlist.file( 'fs_events_files', fileID ).i_pdf_file_name;
                    },
                    dragDrop: false,
                    clearText: 'Remove file'
    
    

    But it did not work. The upload work, and the Database show an new entry. It did not update the exist file data.

    Andreas

  • allanallan Posts: 61,710Questions: 1Answers: 10,103 Site admin

    My point is that it should use fs_events.fileID not fs_events_files.fileID. You want to edit the value of fs_events.fileID.

    You could use this example as a reference for how it can be implemented.

    Allan

  • Andreas S.Andreas S. Posts: 207Questions: 73Answers: 4

    I change this and it works, but the upload creates a new entry in thefs_events_filesdatabase with a new fileID and did not use the entry that exist. If I delete the uploaded file with the editor, it removes the fileID in the fs_eventsDatabase, but did not remove the entry in the fs_events_filesDatabase.
    An other Problem if I want chance the uploaded file to a new one, I have the same problem I describe above.

    Andreas

  • allanallan Posts: 61,710Questions: 1Answers: 10,103 Site admin

    The file upload is async from the rest of the form. It will create the new row in the file storage table immediately when the file is uploaded and then use that row's id for the file id in the table you are editing.

    The result is that you can end up with orphaned files. The Editor manual discusses this and how to handle it.

    Allan

This discussion has been closed.