EE 5.2.6

I've written an add-on that takes date parameters and gets an order report from an Amazon seller account using the Amazon MWS API. The result for this operation is a nice, big XML object.

What I would like to do with this object is save it as a .txt file, along with a few other fields, in a channel entry.

I already have the functionality to save the result as a channel entry using the ee model class. I tried saving the object as a string in a text field but there's just too much data to do this.

What I need to know is how to take the xml object and save it as a .txt file with the channel entry.

I've played around with this suggestion but honestly I'm confused by it and there's no documentation that I can find that relates to this specific question.

This is what I'm currently playing around with. ($title has a dynamically created value)

    $file = ee('Model')->make('File');
    $file->title = $title;
    $file->file_name = $title . '.txt';
    $file->upload_location_id = '2';

It doesn't save anything and isn't throwing an error so I'm not sure what I need to change. This also does nothing with the actual xml data. I need to be able to take the XML object, put it into a .txt file, and save that file with a channel entry.

I'm relatively sure there is a way to do this using the ee model class. If I'm wrong, please point me in the right direction.


1 Answer 1


By using File model you can only insert the data into table named exp_files. By using filemanager library you can upload the file.

What you should do is first write the code to create the file onto server and writing content into the file. After that you should try to upload the file using filemanager library.

Hope this will works for you.

  • Thanks a lot for your reply! I do have some questions. I found this documentation, which, if this is all there is, is woefully inadequate: docs.expressionengine.com/latest/development/extension-hooks/… There is code to do additional processing after file is saved or deleted: $this->extensions->call('file_after_save', $file_id, $data); if ($this->extensions->end_script === TRUE) return; Is this all it takes to save a file? I says next to nothing about what $data is, and how do I know what the $file_id is?
    – Shayne
    Sep 4, 2019 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.