Get the filename of the new uploaded file.

Get the filename of the new uploaded file.

classic12classic12 Posts: 228Questions: 60Answers: 4

Is this available ?

I see I can use alert ('editorQuotes.file( 'files', fileId ).web_path);

but this alerts on the files.

How do I get the filename of the one I have just uploaded ?

Cheers

Steve Warby

Answers

  • classic12classic12 Posts: 228Questions: 60Answers: 4

    I am using the upload-many script to upload the files in the editor.
    Is there a fileUploaded event I can get the info from?

    Cheers

    Steve Warby

  • allanallan Posts: 61,695Questions: 1Answers: 10,102 Site admin

    If the server sends back information about the file, including the file name, then yes, you could get it that way - ...file( 'files', field ).fileName for example. This depends on what is being stored in the database though.

    In terms of events, actually no. It triggers events once the file has been uploaded, but not prior to the upload.

    What information are you storing in the database?

    Allan

  • classic12classic12 Posts: 228Questions: 60Answers: 4

    I am using an editor and have added a CKEditor to edit one of the fields.

    Within the CKEditor I am adding the images that I upload. So I cam have a field with all the information in.

    So at the moment once an image has been uploaded I right click the thumbnail get the new file image url and manually add that in the ckeditor.

    My aim is on new file upload.

    1. Get the existing data in the CKEditor.
    2. Add the new file ( with the necessary <scr added to display it )
    3. Update the CKEditor then manually 'fluff' up the layout.

    This is how I am getting the details column here www.surplusanywhere.com/surplusAnywhere6 which I then offer a button so the client can email that particular deal to themselves ( eventually )

    PS I just noticed I can drag and drop an image into here.

    Cheers

    Steve Warby

  • allanallan Posts: 61,695Questions: 1Answers: 10,102 Site admin

    I wonder if it might actually be easier to use CKEditor's own file upload if you want to embed the images into the text of CKEditor.

    The other option is to use the render option in the uploadMany field type to display not only the image as you currently are, but also the URL to get the image (you already have that - its just in an img tag, so you could display that as well as the image, allowing it to be copy / pasted into CKEditor.

    Allan

  • classic12classic12 Posts: 228Questions: 60Answers: 4

    Thanks Allan,

    from here https://editor.datatables.net/reference/field/uploadMany I have added the 'show new file added'.

    I am presuming this is the event I need to get the new filename and add the image to the CKEditor.

    I don't get an alert ?

    getQuotes=function(){
            editorQuotes = new $.fn.dataTable.Editor( {
            ajax: "http://www.xxxx.com/xxxx/upload-many.php",
            
            table: "#dtQuotes",
            fields: [ 
                {
                    label: "Quote ID:",
                    name: "quotes.quoteID"
                },{
                    label: "Cust ID:",
                    name: "quotes.custID"
                   },
                   {
                    label: "Status:",
                    name: "quotes.status",
                    type: 'radio',
                    options: [
                        'active',
                        'dead',
                        'sold',
                        'onHold']},
                {
                    label: "Quote Title:",
                    name: "quotes.quoteTitle"
                }, {
                    label: "Notes:",
                    name: "quotes.notes",
                    type : 'ckeditor'
                }, {
                    label: "Notes Internal:",
                    name: "quotes.notesInternal"
                },{
                    label: "Images:",
                    name: "files[].id",
                    type: "uploadMany",
                    display: function ( fileId, counter ) {
                        //alert('run code here to add filename to editor ' + 'http://www.surplusanywhere.com'+editorQuotes.file( 'files', fileId ).web_path);
                        return '<img src="'+editorQuotes.file( 'files', fileId ).web_path+'"/>' + 
                        'http://www.surplusanywhere.com'+editorQuotes.file( 'files', fileId ).web_path;
                        //alert('run code here to add the new filename to editor ' + 'http://www.surplusanywhere.com'+editorQuotes.file( 'files', fileId ).web_path);
                    },
                    noFileText: 'No images'
                }
                
    
                    ]
            
    
                } );
        
            editorQuotes.on('initEdit', function () {
            //alert('edit mode');
                //editorQuotes.set( 'custID', selectedCustID );
                editorQuotes.disable(["quotes.quoteID"]);
            });
            
             editorQuotes.on('initCreate', function () {
             //alert('on create ');
                editorQuotes.set( 'quotes.custID', selectedCustID );
                editorQuotes.disable(["quotes.quoteID"]);
            });
            editorQuotes.title('Edit entry').buttons('Update').edit(this);
            editorQuotes.on( 'create', function ( e, type ) {
            // Type is 'main', 'bubble' or 'inline'
            alert( 'new row created' );
         
            // show new file added.
            $( editorQuotes.field( 'files[].id' ).input() ).on( 'upload.editor', function (e, val) {
            alert( 'Images field has changed value', val );
            } );
           
    } );
    
  • classic12classic12 Posts: 228Questions: 60Answers: 4

    Cancel this sorry i'd put the show new file added within the Edit Entry.....

    I was drinking last night

  • classic12classic12 Posts: 228Questions: 60Answers: 4

    Hi Guys,

    I'm struggling on the logic ( as usual) of how to obtain just the added filename.

    Eg say I have 3 images files already.
    val gives me
    217,218,219

    I add another images

    val gives me
    217,218,219,220

    I need to get just 220.

    But each time I add val gets overwritten.

    Cheers

    Steve Warby

  • allanallan Posts: 61,695Questions: 1Answers: 10,102 Site admin

    Do you have the file name in the database? If so, you could use editor.file( 'tableName', id ).fileName or similar (file()). It really depends on what you are saving in the database about the files. Can you show me your server-side code for the upload?

    Allan

This discussion has been closed.