How do I access the upload file event.

How do I access the upload file event.

classic12classic12 Posts: 228Questions: 60Answers: 4

Hi guys,

I am using the editor with the 'upload-many.php' script.
I also use CKEditor to produce some formatted text with the DESC field.
I create a record then drag & drop image files onto the editor.
I then cut and paste the following into the html source of the DESC.

<p><img alt="" src="http://www.surplusanywhere.com/upload/165.jpg" style="box-shadow:grey 10px 10px 5px; display:block; margin:30px auto; width:75%" /></p>

I do this for each image and replace 165 with the current filename. This gives me nice formatted images.

I now want to do this programatically with each file upload.

So on file uploaded get the uploaded file name ( e.g. 265 )
Update the current DESC field with '.... www.surplusanywhere.com/upload/265.jpg ' added to the end of the data.
Do this for each file upload.

Any ideas ?

Cheers

Steve Warby.

Answers

  • colincolin Posts: 15,169Questions: 1Answers: 2,589

    Would the uploadXhrSuccess event do the trick?

    C

  • classic12classic12 Posts: 228Questions: 60Answers: 4

    Thanks Colin,

    I have that event working and I can see the json returned.

    {"data":[],"files":{"files":{"612":{"id":"612","filename":"cloudImage1 copy.png","filesize":"304909","web_path":"/upload/612.png","system_path":"/home/wilseayd/surplusanywhere.com/upload/612.png"}}},"upload":{"id":"612"}}
    
    

    I can get 612.png as the filename.

    I now create the string

    <p><img alt="" src="http://www.surplusanywhere.com/upload/
    612.png
    " style="box-shadow:grey 10px 10px 5px; display:block; margin:30px auto; width:75%" /></p>
    

    In the editor I have the following:

     {
                    label: "Notes:",
                    name: "quotes.notes",
                    type : 'ckeditor'
                }, 
    

    which is the 'quotes.notes' field I want add the above string into.

    How do I add this please ?

    Cheers

    Steve Warby

  • classic12classic12 Posts: 228Questions: 60Answers: 4

    I found it ( I had used this in another project a while ago)

    I access the data s follows:

    alert(editorQuotes.field( 'quotes.notes' ).val());
    
  • classic12classic12 Posts: 228Questions: 60Answers: 4

    The complete routine is here.
    This will save me hours........LOL

                   editorQuotes.on( 'uploadXhrSuccess', function ( e, fieldName, json ) {
                    console.log(json);
                    var newID= json["upload"].id;
                    var webPath = json["files"]["files"][newID].web_path;
                    var filename = webPath.substring(webPath.lastIndexOf('/'));
                    var filename = filename.replace("/", "");
                    lineToAdd = '<p><img alt="" src="http://www.surplusanywhere.com/upload/'+filename+'" style="box-shadow:grey 10px 10px 5px; display:block; margin:30px auto; width:75%" /></p>';
                    var existingData = editorQuotes.field( 'quotes.notes' ).val();
                    var newData = existingData + "<br />" + lineToAdd;
                    editorQuotes.set( 'quotes.notes', (newData));
                    
              } ); 
    

    This works okay when I drag and drop a few files at once as well.

    Cheers

    Steve Warby

  • colincolin Posts: 15,169Questions: 1Answers: 2,589

    Hi Steve,

    Excellent, glad it's all working!

    Cheers,

    Colin

This discussion has been closed.