Can someone please direct me to a resource or give me some pointers on:

  • How to upload a csv file to wordpress (media uploader or alternate methods, ajax powered preferred)
  • Access that file so I can read the contents

I am not looking for a plugin as this is a custom file that I need to read and process inside a plugin. Ideally, this workflow is desired: Choose a file > Click Upload > Plugin accesses the file after upload and processes file content > Plugin deletes the file. Bold steps interest me the most.

  • Without describing what "process file contents" means, your question is hard to answer. Commented Feb 3, 2013 at 4:40
  • @chrisguitarguy Basically read the file content and do stuff with it (db and some misc. operations). That part I already have. Thanks! Commented Feb 3, 2013 at 7:29

1 Answer 1

  1. Enable upload of CSV files, which are not in the default allowed files (see here)
  2. Hook into add_attachment action hook to detect when the desired file is uploaded
  3. Do whatever you need to do using that hook, then trigger wp_delete_attachment once the file has been processed.

Depending on what you want to do, it may be beneficial to craft your own upload setup outside the default Media Manager where it would be easier to detect when a file uploaded should be processed by your plugin.

  • I ended up using the default media uploader and am hooking into 'wp_handle_upload', which gives me the file path. Thanks! Commented Feb 5, 2013 at 2:43
  • Glad to help! If everything worked out, would you mind marking this question as resolved? Thanks!
    – Dan
    Commented Feb 5, 2013 at 7:33

Your Answer

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

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