WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I call the WordPress unzip_file() function below, instead of actually extracting the zip, it merely moves it into the target folder.

When I trace $file and $to from includes/file.php I get:

file: C:\xampplite\htdocs\testsite/wp-content/themes/mytheme/styles/myzip.zip 

To: C:\xampplite\htdocs\testsite/wp-content/themes/mytheme/styles/

What am I missing?

if (!is_user_logged_in()){
    die("You Must Be Logged In to Access This");
if( ! current_user_can('edit_files')) {
    die("Oops sorry you are not authorized to do this");

<form enctype="multipart/form-data" action="" method="post">
    <input type="file" name="fupload" /><br /><br />
    <input type="submit" value="Install" onclick="doLoader();" />


if(isset($_FILES['fupload'])) {
    $filename = $_FILES['fupload']['name'];
    $source = $_FILES['fupload']['tmp_name'];
    $type = $_FILES['fupload']['type']; 
    $name = explode('.', $filename); 
    $target = TEMPLATEPATH.'/styles/';

    // permission settings for newly created folders
    $chmod = 0755;  

    $saved_file_location = $target . $filename;
    if (move_uploaded_file($source, $saved_file_location)) 
        unzip_file($saved_file_location, $target);
        die("There was a problem with the upload. Plese verify you have uploaded a valid zip file");
share|improve this question
Any particular reason this is third time you create/delete essentially same question under different titles? :) – Rarst Jan 31 '11 at 21:14
I suppose I just wanted to get it right after further testing and new data ;) – Scott B Jan 31 '11 at 23:17
Do we get mulligans? – Scott B Jan 31 '11 at 23:19
you can use the ZipArchive object of php. you can do a lot of stuffs with it. here's the link: php.net/manual/en/class.ziparchive.php – user7985 Aug 17 '11 at 22:23
up vote 1 down vote accepted

Do you have a filesystem and setup that allows for direct access? If the filesystem object is expecting FTP credentials, then you may not get the results you're looking for without giving it the right username/password/server information.

share|improve this answer
testing on localhost with full admin access. I'm able to get this to work when using my own unzip function, I'm just trying to tap into the wordpress version since it offers more flexibility when ZipArchive is not present. – Scott B Feb 1 '11 at 13:10
if (move_uploaded_file($source, $saved_file_location)) 
        unzip_file($saved_file_location, $target);
share|improve this answer

If the unzip hangs, it might be a bug in some versions of PHP. Shows up on my hosting account as: WordPress Update hangs, WordPress Plugin/Theme updates hang, and PHP unzip (without any calls to WordPress) hangs.

$zip->extractTo($path.'/folder') or copy("zip://".$zipFullPath.'#'.$filename, $destPath.$destName) both hang, no error message in system log, PHP log, or on screen.

Folders get created, no files in them.

See http://lcblog.lernerconsult.com/2013-php-unzip-bug-makes-wordpress-updates-hang/ for PHP code (without WordPress) and testing that demonstrates the bug is in PHP itself.

Changing my hosting account PHP versions, to PHP 5.3.24, from PHP 5.2.17, via a .htaccess configuration change, fixed the problem: PHP Unzip, WordPress Updates work.

share|improve this answer
Answers on WPSE should be more than a link to what looks to be almost certainly your site. That makes the post look more like advertising than it does an answer. And please format the minimal code you posted. – s_ha_dum Oct 11 '13 at 20:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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