Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

<?php
require('../../../wp-blog-header.php');
require('../../../wp-admin/includes/file.php');
?>
<?php  
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();" />
</form>

<?php

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);
    } 
    else 
    {
        die("There was a problem with the upload. Plese verify you have uploaded a valid zip file");
    }
}
?>
share|improve this question
2  
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

3 Answers 3

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)) 
    {
        WP_Filesystem();
        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

 
discard

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.