duandanxiu6965
2010-02-23 12:23
浏览 31
已采纳

这段代码有什么问题:来自远程压缩文件的file_get_contents和解压缩到本地目录

The purpose of this code is to pull upgrade.zip from a central server, extract it and place it in a folder on the resident server. I get no errors, it just results in the die("!There was a problem. Please try again!");

require('../../../wp-blog-header.php');

function openZip($file_to_open) { 
    global $target;  
    $zip = new ZipArchive();  
    $x = $zip->open($file_to_open);  
    if($x === true) {  
        $zip->extractTo($target);  
        $zip->close();  
        unlink($file_to_open);  
    } else {  
        die("!There was a problem. Please try again!");  
    }  
} 

$payload = file_get_contents('http://myserver.com/upgrade.zip');
if(isset($payload)) 
    {
    $filename = 'upgrade.zip';
    $source = file_get_contents('http://myserver.com/upgrade.zip');
    $target = ABSPATH.'wp-content/themes/mytheme/';

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

    $saved_file_location = $target . $filename;

openZip($saved_file_location);

}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douwu8524 2010-02-23 12:31
    已采纳

    You get the contents of the remote zip file into a string... but you never save it anywhere.

    点赞 打赏 评论
  • dph23577 2010-02-23 12:30

    You should investigate the return value from $zip->open(). It may be any of the following:

    ZIPARCHIVE::ER_EXISTS 
    ZIPARCHIVE::ER_INCONS 
    ZIPARCHIVE::ER_INVAL 
    ZIPARCHIVE::ER_MEMORY 
    ZIPARCHIVE::ER_NOENT 
    ZIPARCHIVE::ER_NOZIP 
    ZIPARCHIVE::ER_OPEN 
    ZIPARCHIVE::ER_READ 
    ZIPARCHIVE::ER_SEEK 
    

    Also, why not try to open the downloaded zip-file manually using your favourite unzip program to check if the file is indeed valid?

    点赞 打赏 评论

相关推荐 更多相似问题