8

同じサーバー内のある仮想ホストから別の仮想ホストにcurlを使用してzipファイルをダウンロードしようとしています。Zipファイルには*.phpファイルと*.jpgファイルが含まれています。

問題は次のとおりです。次のように、JPGファイルが破損することがあります。

jpgファイル

これが私のコードです:

$out = fopen(ABSPATH.'/templates/default.zip','w+'); 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_FILE, $out); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_URL, 'http://share.example.com/templates/default.zip'); 
curl_exec($ch); 
curl_close($ch); 


$zip = new ZipArchive;
if ($zip->open(ABSPATH.'/templates/default.zip') === TRUE) 
{
    if($zip->extractTo(ABSPATH.'/templates'))
    {
        echo 'OK';
    }

    $zip->close();
} 

//$zip->close();

jpgがどうなるかわかりません。また、pclzip.lib.phpを使用してみましたが、うまくいきませんでした。この問題を解決する方法は?

前もって感謝します

4

2 に答える 2

1

最後に、何が問題なのかを見つけました。

nginx構成ファイルを変更するとき、私はNginx Webサーバーを使用しています:

sendfile on;

なりました

sendfile off;

私のイメージはもう壊れていません。したがって、phpやcurlの問題ではありません。興味深い記事: http://technosophos.com/node/172

于 2012-06-09T16:55:14.773 に答える
1

Have you tried downloading the file via curl and unzipping it normally (i.e. without php)? To figure out whether the download causes the problem or the unzip.

You might also try to replace one of both parts using shell_exec (wget instead of curl, unzip instead of ZipArchive). I mean just for debugging, not for production maybe.

于 2012-06-03T10:29:30.013 に答える