tags:

views:

25

answers:

1

I've got a pretty popular WordPress theme that has a template switcher (basically just changes the stylesheet assigned to the theme for a completely different look and stores this as setting in the db).

The way I do this is that I have a "styles" directory under my theme folder and inside of that, I have a single folder for every one of my templates that work with the theme.

Inside each of these folders is a stylesheet, along with any images the template needs.

I'd like to create an uploader in my theme options panel that allows one to select a zip file from their PC and install a new template to the theme.

Basically, I suppose I'm just looking for an upload routine that can take a zip file, extract it and place it in my theme's style folder. If there is already a folder by the same name, I'd like the routine to prompt for overwrite or rename.

Any ideas?

This appears to be the most promising thus far. I just need some tips on how to get this integrated with an file > uploader widget.

// create object
$zip = new ZipArchive() ;

// open archive
if ($zip->open(‘archive. zip’) !== TRUE) {
die (‘Could not open archive’);
}

// extract contents to destination directory
$zip->extractTo(‘/ tmp/extracted/ ‘);

// close archive
// print success message
$zip->close();
echo ‘Archive extracted to directory’;
A: 

Might be worth checking out the PHP filesystem functions: http://www.php.net/manual/en/ref.filesystem.php

If you've tried with some code, I might be able to help some more.

Ettiene
Thanks for the link Ettiene. I've updated my question with the sample code bits that I believe will form the guts of the routine. I just need some help creating the browser interface thats needed to allow the user to upload their zip file.
Scott B
Also, If I create a file/browse widget, my assumption is the "archive.zip" in the above example becomes "whatever.zip" according to what the file name the user is uploading, correct?
Scott B