ERROR TO UPLOAD CSV FILE : A server error occurred while uploading the file
ERROR TO UPLOAD CSV FILE : A server error occurred while uploading the file
impex09
Posts: 45Questions: 20Answers: 0
Hi, Im using the next script , but when I tried to upload the CSV file I received a error Message: A server error occurred while uploading the file.
Can you help me please????
thank you
/*
* Editor client script for DB table impx_ccps_cat_products
* Created by http://editor.datatables.net/generator
*/
// Display an Editor form that allows the user to pick the CSV data to apply to each column
function selectColumns ( editor, csv, header ) {
var selectEditor = new $.fn.dataTable.Editor();
var fields = editor.order();
for ( var i=0 ; i<fields.length ; i++ ) {
var field = editor.field( fields[i] );
selectEditor.add( {
label: field.label(),
name: field.name(),
type: 'select',
options: header,
def: header[i]
} );
}
selectEditor.create({
title: 'Map CSV fields',
buttons: 'Import '+csv.length+' records',
message: 'Select the CSV column you want to use the data from for each field.'
});
selectEditor.on('submitComplete', function (e, json, data, action) {
// Use the host Editor instance to show a multi-row create form allowing the user to submit the data.
editor.create( csv.length, {
title: 'Confirm import',
buttons: 'Submit',
message: 'Click the <i>Submit</i> button to confirm the import of '+csv.length+' rows of data. Optionally, override the value for a field to set a common value by clicking on the field below.'
} );
for ( var i=0 ; i<fields.length ; i++ ) {
var field = editor.field( fields[i] );
var mapped = data[ field.name() ];
for ( var j=0 ; j<csv.length ; j++ ) {
field.multiSet( j, csv[j][mapped] );
}
}
} );
}
(function($){
$(document).ready(function() {
var editor = new $.fn.dataTable.Editor( {
ajax: 'php/table.referencia_campo.php',
table: '#referencia_campo',
fields: [
{
"label": "convenio:",
"name": "convenio"
},
{
"label": "ficha_deposito:",
"name": "ficha_deposito"
},
{
"label": "importe:",
"name": "importe"
},
{
"label": "concepto:",
"name": "concepto"
},
{
"label": "campo_conocimiento:",
"name": "campo_conocimiento"
},
{
"label": "Campo Clave:",
"name": "clave_campo"
},
{
"label": "estatus:",
"name": "estatus"
}
]
} );
// Upload Editor - triggered from the import button. Used only for uploading a file to the browser
//ajax: 'php/table.ship_createevent.php',, or
// Add ajax: 'php/table.ship_createevent.php'
var uploadEditor = new $.fn.dataTable.Editor( {
fields: [ {
label: 'CSV file:',
name: 'csv',
type: 'upload',
ajax: function ( files ) {
// Ajax override of the upload so we can handle the file locally. Here we use Papa
// to parse the CSV.
Papa.parse(files[0], {
header: true,
skipEmptyLines: true,
complete: function (results) {
if ( results.errors.length ) {
console.log( results );
uploadEditor.field('csv').error( 'CSV parsing error: '+ results.errors[0].message );
}
else {
uploadEditor.close();
selectColumns( editor, results.data, results.meta.fields );
}
}
});
}
} ]
} );
var table = $('#referencia_campo').DataTable( {
dom: 'Bfrtip',
ajax: 'php/table.referencia_campo.php',
columns: [
{
"data": "id_referencia"
},{
"data": "convenio"
},
{
"data": "ficha_deposito"
},
{
"data": "importe"
},
{
"data": "concepto"
},
{
"data": "clave_campo"
},
{
"data": "campo_conocimiento"
},
{
"data": "estatus",
render: function (estatus) {
return estatus == 1 ?
'Asignado'
:
'Disponible';
},
}
],
select: true,
lengthChange: false,
buttons: [
{ extend: 'create', editor: editor, text: 'Nueva Referencia Bancaria' },
{ extend: 'edit', editor: editor, text: 'Editar Referencia Bancaria' },
{ extend: 'remove', editor: editor, text: 'Eliminar Referencia Bancaria' },
{extend: 'csv',
text: 'Exportar a CSV',
className: 'btn-space',
exportOptions: {
orthogonal: null
}
},
{
text: 'Importar CSV',
action: function () {
uploadEditor.create( {
title: 'Importar archivo CSV'
} );
}
},
{
extend: 'selectAll',
className: 'btn-space',
text: 'Seleccionar Todo'
},
{
extend: 'selectNone',
className: 'btn-space',
text: 'Cancelar Selección'
},
],
"language": {
"decimal": ",",
"thousands": ".",
"info": "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
"infoEmpty": "Mostrando registros del 0 al 0 de un total de 0 registros",
"infoPostFix": "",
"infoFiltered": "(filtrado de un total de _MAX_ registros)",
"loadingRecords": "Cargando...",
"lengthMenu": "Mostrar _MENU_ registros",
"paginate": {
"first": "Primero",
"last": "Último",
"next": "Siguiente",
"previous": "Anterior"
},
"processing": "Procesando...",
"search": "Buscar:",
"searchPlaceholder": "Palabra clave",
"zeroRecords": "No se encontraron resultados",
"emptyTable": "Ningún dato disponible en esta tabla",
"aria": {
"sortAscending": ": Activar para ordenar la columna de manera ascendente",
"sortDescending": ": Activar para ordenar la columna de manera descendente"
},
//only works for built-in buttons, not for custom buttons
"buttons": {
"create": "Nuevo",
"edit": "Cambiar",
"remove": "Borrar",
"copy": "Copiar",
"csv": "fichero CSV",
"excel": "tabla Excel",
"pdf": "documento PDF",
"print": "Imprimir",
"colvis": "Visibilidad columnas",
"collection": "Colección",
"upload": "Seleccione fichero...."
},
"select": {
"rows": {
_: '%d filas seleccionadas',
0: 'clic fila para seleccionar',
1: 'una fila seleccionada'
}
}
} ,
//
/*buttons: [
{ extend: 'create', editor: editor },
{ extend: 'edit', editor: editor },
{ extend: 'remove', editor: editor },
{
extend: 'csv',
text: 'Export CSV',
className: 'btn-space',
exportOptions: {
orthogonal: null
}
},
{
text: 'Import CSV',
action: function () {
uploadEditor.create( {
title: 'CSV file import'
} );
}
},
{
extend: 'selectAll',
className: 'btn-space'
},
'selectNone',
],*/
"rowCallback": function( row, data, index ) {
if (data.estatus == 1) {
$('td', row).css('background-color', '#FF5733');
}
}
} );
} );
}(jQuery));
Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This discussion has been closed.
Answers
The XHR Response :
{"data":[],"options":[],"files":[]}
DevTools failed to load SourceMap: Could not load content for http://localhost/ccps_unam/Sistema_Pagos/unam/css/bootstrap.min.css.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE
If you are getting a server error then the place to start looking is at the server logs to track down the error. Let us know what you find.
Kevin
humm Datatables generate a logs?
That is not the problem.
Where did you see this message?
Is this the response you get when you see the
A server error occurred
message? The place to look then is the server that sent this response.Kevin
When you say, look at the server, exactly what does it mean?
The server where
table.referencia_campo.php
exists.Kevin
well Im using IIS as web server,
all the site has the full permissions.
in other example works it, but in this case doesnt work
So check your IIS logs.
Yep, as everyone says, you need to check the server IIS logs - as that would give more information. It could be anything - badly spelt database name in the scripts, missing files, etc - so we can't guess what it would be, but the logs will give the details we need to progress this,
Colin