Custom Plugin File Upload Form Submission
-
Ok so I have a WordPress plugin developed and one of the features of it I wanted to add, was an area in the admin where the user can upload a CSV, and when the form is submitted to execute a big ole script I’ve writted.
So I’ve got the admin form created just like so:
(Located in a file “PLUGIN_FOLDER/admin/partials/admin-bookings-import-display.php)
<div id="poststuff"> <div id="post-body" class="metabox-holder"> <div id="post-body-content"> Please upload your XML file here <form action="<?php echo admin_url('admin-post.php'); ?>" enctype="multipart/form-data" method="post"> <p>Choose a file: <input type="file" name="xml-file" id="xml-file" /></p> <?php submit_button('Upload') ?> </form> </div> </div> <br class="clear"> </div>The issue I’m having now, is working out how I can execute my script stuff when this form is submitted?
All of my script code is located in a file here: PLUGIN_FOLDER/admin/bookings-import.php
But how to I make my form submission directly call to this file without referencing the file directly?
Another point, because I’m using a file upload, do I need to physically save this file before I can do anything with it’s contents? I got the script working while using a physical file saved on my machine but obviously i need to get this working using the one that was uploaded within the form.
And before anyone suggests using a normal file upload plugin, my script has to do a bunch of data manipulation with the contents of the CSV before inserting it into my DB. This is already set up correctly.
Thanks
The topic ‘Custom Plugin File Upload Form Submission’ is closed to new replies.