Parse Error upload function
Parse Error upload function
Andreas S.
Posts: 208Questions: 74Answers: 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 );
}
}
]
});
This discussion has been closed.
Replies
Is the PHP you posted
evm_server_processing.php
? I don't seei_pdf
on line 101 and I've just run it through the PHP linter and it checks out as valid syntax.Allan
It is the correct file. I removed the file header Information. the error line is 92
Andreas
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
**PHP **new:
Is coming about because you are trying to store all files here:
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
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 asI_ÖJM+ÖBM-Schwimmen_2016.pdf
Andreas
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
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
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 :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
https://wordpress.org/support/topic/functionphp-parse-error-1/
a joke?
What is
edit_mlist
? Is it a DataTable instance or an Editor instance? It should be a DataTables instance (seefile()
). I have a feelingedit_mlist
might be an Editor instance.Regards,
Allan
meetlist
is the datatable andedit_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.
I want to show the filename of the pdf that is stored in i_pdf and so on.
Andeas
Can you give me a link to the page so I can debug the live code please.
Thanks,
Allan
http://www.a-timing.wien/finswimming/index.php?l=en&mo=mli
Andreas
Could you change:
to be:
which I think should address the error.
Regards,
Allan
ok I change it, but the editor show no File.
Andreas
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 theltv_events_files
table? That will probably be a bit easier to work with as that's how the examples work.Allan
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
My suggestion would be that your
ltv_events
table should have a column that references theltv_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
I have now chanced my database model.
Database model:
JS:
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
The client-side is sending:
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
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.
Its sending that parameter because the Editor field definition for the upload field contains:
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
I change the line, but it did not work. See screenshot of the error
Andreas
Did you update the PHP script to reflect that the
upload
should be on thefs_events.fileID
field?Allan
I update the php to:
and the js script to
But it did not work. The upload work, and the Database show an new entry. It did not update the exist file data.
Andreas
My point is that it should use
fs_events.fileID
notfs_events_files.fileID
. You want to edit the value offs_events.fileID
.You could use this example as a reference for how it can be implemented.
Allan
I change this and it works, but the upload creates a new entry in the
fs_events_files
database 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 thefs_events
Database, but did not remove the entry in thefs_events_files
Database.An other Problem if I want chance the uploaded file to a new one, I have the same problem I describe above.
Andreas
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