Jump to content

PHP help to upload CSV to WordPress MySQL options table


advantus

Recommended Posts

I'm wasted almost an entire day trying to figure this out.  So I'm eating crow and coming to the gurus to help me out.

 

Here's what I'm trying to accomplish and I already have it 1/2 done.  I have a WordPress theme that I need to enable users to export and import some of the data from the options table in WordPress.

 

Here's the structure of the wp_options table:  option_id (autoincrement), blog_id, option_name, option_value, and autoload

 

I already have the export functionality complete, so I end up with the filtered records I want, with column titles, no option_id in the export and it saves as a prenamed csv just like it should.

 

Now I'm trying to build the function that can take that csv file (or any other csv exported from the same theme, just with different settings) and upload it back into the wp_options table. It will obviously require the deletion of any existing values, which isn't a problem because I already have the 'delete' button coded and working to remove those.

 

I've tried a bunch of available scripts, but I'm having problems getting the CSV uploaded as a temp file to the server, then getting the data extracted properly into the table. The option_id obviously needs to assign itself on import, so that's why I didn't include that column in the export csv.

 

I don't need any of the database connection script, because that's already built into the wp-config file that's required at the top of the file.

 

The csv file comes from the file field in the upload form, then when they click on the 'Import' button I want the CSV to be uploaded and imported into the proper table, which is:

 

$table = $wpdb->prefix . 'options';

 

Does anyone have any scripts that would work to do this?  I'm at wits end.

 

Thanks in advance.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.