Getting warnings with editor file upload
Getting warnings with editor file upload
mRender
Posts: 151Questions: 26Answers: 13
I'm getting a couple of warnings on my first try on the file upload. I get a couple of warnings about calls to the upload function when I try to add a file to the editor.
include( "DataTables-1.10.7/extensions/Editor-1.4.2/php/DataTables.php" );
// Alias Editor classes so they are easy to use
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Join,
DataTables\Editor\Upload,
DataTables\Editor\Validate;
$data = Editor::inst( $db, 'files', 'FID' )
->field(
Field::inst( 'files.FID' ),
Field::inst( 'files.file_id' )
->options( 'parts', 'part_id', 'fgc_number' ),
Field::inst( 'files.path' )
->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/uploads/__ID__.__EXTN__' ) )
)
->LeftJoin( 'parts', 'parts.part_id', '=', 'files.file_id' )
->process($_POST)
->data();
// Send it back to the client
echo json_encode( $data );
Here is my js
$(document).ready(function() {
editor = new $.fn.dataTable.Editor( {
processing: true,
serverSide: true,
ajax: "dt_files.php",
table: "#files",
fields: [ {
label: "FID:",
name: "files.FID"
},{
label: "file_id:",
name: "files.file_id",
type: "select"
},{
label: "path:",
name: "files.path",
type: "upload"
}
]
} );
$('#files').DataTable( {
dom: "Tfrtip",
pageLength: 25,
paging: true,
info: false,
idSrc: "files.FID",
ajax: "dt_files.php",
columns: [
{ data: "files.FID" },
{ data: "files.file_id" },
{ data: "files.path" }
],
"order": [[ 0, 'asc' ]],
tableTools: {
sRowSelect: "os",
sSwfPath: "DataTables-1.10.7/extensions/TableTools/swf/copy_csv_xls_pdf.swf",
aButtons: [
{ sExtends: "editor_create", editor: editor },
{ sExtends: "editor_edit", editor: editor },
{ sExtends: "editor_remove", editor: editor },
"print",
{
"sExtends": "collection",
"sButtonText": "Save",
"aButtons": [ "csv", "xls", "pdf" ]}
]
}
} );
} );
Here is the website if you want to take a look at the warnings.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Sounds like the
uploads
directory might not exist in your host's virtual root. Does it?Also if you want to use
__ID__
you need to use theUpload->db()
method to tell it information about the database table you want to store the file information in (otherwise the id won't exist!).Allan
Whoops.
Should have been
And I just turned it into this:
That should suffice with that I need to do here.
I'm also having an issue with webPath being undefined. I'm trying to implement this code here:
Is there something else that I need to do? When I add an image in the editor it throws the webPath undefined error.
I tried something like this to get the webPath and added fileName, fileSize and webPath to my database but I'm still getting webPath errors.
WHOOPS! Got it.
I was using image.webPath instead of my table name of files. I'm an idiot.
Good work Allan on the file uploader. Some pretty cool stuff here!
Hi,
Great to hear you've got it working now! Upload is certainly one of the more complicated parts of Editor - there was only so much complexity that I was comfortable with abstracting out (a trade off between flexibility and the initial learning curve).
Allan