1

このコードの目的は、リモートサーバーからupdate.zipファイルを取得し、解凍してローカルディレクトリに保存し、更新されたファイルを更新、上書き、または作成することです。

私はこれの非cURLバージョンをほぼ機能させていますが、むしろこのバージョンを使用したいと思います。私が抱えている最初の問題は、tmpフォルダーへのパスが正しくないことです。それをスニッフィングするより良い方法が必要です(一時的にハードコーディングされています)...

2番目の問題は、コードが機能していないが、エラーがスローされていないことです。$ xブランチを実行しますが、zip抽出は行われません。

require('../../../wp-blog-header.php'); //enables wp security check and ABSPATH

    $payload = file_get_contents('http://myserver.com/upgrade.zip'); //grab the file from the remote server
    $target = ABSPATH .'wp-content/themes/mytheme/'; // this is the destination for the unzipped files

openZip($payload); 

function openZip($file_to_open, $debug = false) { 
    global $target;
    $file = ABSPATH . '/tmp/'.md5($file_to_open).'.zip'; //this should be home/myfolder/tmp but ABSPATH is giving the wrong path to the tmp directory.
    $client = curl_init($file_to_open);
    curl_setopt($client, CURLOPT_RETURNTRANSFER, 1);  
    $fileData = curl_exec($client);

    file_put_contents($file, $fileData);

    $zip = new ZipArchive();  
    $x = $zip->open($file);  
    if($x === true) {  //this is true, but no zip extraction?
        $zip->extractTo($target);  
        $zip->close();  

        unlink($file);  
    } else {
        if($debug !== true) {
            unlink($file);
        }  
        die("There was a problem. Please try again!");  
    }  
}
4

1 に答える 1

0

ここで最も可能性の高い原因は、openZip 内の file_put_contents() 呼び出しで実際に zip ファイル データを書き込んでいないことです。長さゼロのファイルを $zip->open() に渡すと、(bool)true何も抽出できないことは明らかですが、喜んで を返します。この例を参照してください。

于 2010-11-10T10:09:33.790 に答える