2014-01-23 4 views
1

curl을 사용하여 원격 서버에서 zip 파일을 다운로드하고 wordpress 테마 디렉토리에 압축을 풉니 다. PHP를 통해 압축을 풀면 19 번 zip 파일이 없다는 것을 발견 한 결과가보고되지 않습니다. 그러나 디렉토리를 확인하면 zip 파일이 있습니다. 압축을 풀면 zip.cpgz 파일로 끝납니다. 이것이 내 코드에 문제가 있거나 서버가 파일을 보내는 방법인지 확실하지 않습니다. 여기 내 코드가있다. 감사.압축 해제 후 curl에서 zip 파일을 다운로드하면

$dirpath = dirname(__FILE__); 
$themepath = substr($dirpath, 0, strrpos($dirpath, 'wp-content') + 10)."/themes/"; 
//make call to api to get site information 
$pagedata = file_get_contents("https://ourwebsite/downloadzip.php?industryid=$industry"); 
$jsondata = json_decode($pagedata); 

$fileToWrite = $themepath.basename($jsondata->zip_file_url); 

$zipfile = curl_init(); 
curl_setopt($zipfile, CURLOPT_URL, $jsondata->zip_file_url); 
curl_setopt($zipfile, CURLOPT_HEADER, 1); 
curl_setopt($zipfile, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($zipfile, CURLOPT_BINARYTRANSFER, 1); 
$file = curl_exec($zipfile); 

if ($file == FALSE){ 
    echo "FAILED"; 
}else{ 
    $fileData = fopen($fileToWrite,"wb"); 
    fputs($fileData,$file); 
} 
curl_close($zipfile); 

if (file_exists($fileToWrite)){ 
    $zip = new ZipArchive; 
    $res = $zip->open($fileToWrite); 
    if ($res === TRUE) 
    { 
     $zip->extractTo($themepath); 
     $zip->close(); 
     echo 'Theme file has been extracted.'; 
    } 
    else 
    { 
     echo 'There was a problem opening the theme zip file: '.$res; 
    } 
} 
else{ 
    echo("There was an error downloading, writing or accessing the theme file."); 
} 

답변

-1

이 그것을 수행해야합니다

<?php 
set_time_limit(0); 

$industry = "industryid"; //replace this 
$url = "https://ourwebsite/downloadzip.php?industryid=$industry"; 
$tmppath = "/tmp/tmpfile.zip"; 
$themdir = "/your/path/wp-content/themes/"; 
$fp = fopen ($tmppath, 'w+');//This is the file where we save the zip file 

$ch = curl_init($url); 
curl_setopt($ch, CURLOPT_TIMEOUT, 0); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch, CURLOPT_FILE, $fp); // write curl response to file 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
curl_exec($ch); // get curl response 
curl_close($ch); 
fclose($fp); 


if (file_exists($tmppath)){ 
    $zip = new ZipArchive; 
    $res = $zip->open($tmppath); 
    if ($res === TRUE) 
    { 
     $zip->extractTo($themdir); 
     $zip->close(); 
     echo 'Theme file has been extracted.'; 
    } 
    else 
    { 
     echo 'There was a problem opening the theme zip file: '.$res; 
    } 
} 
else{ 
    echo("There was an error downloading, writing or accessing the theme file."); 
} 
?> 
+0

감사합니다. 나는 당신의 코드와 좀 더 가깝게 일치하도록 코드를 수정했으나 실제 문제가 그 문제를 일으키고 있는지 확실하지 않습니다. 대답 할 수 있니? 다시 한 번 감사드립니다! –

+0

아마도 파일 또는 파일 권한을 저장 한 임시 위치 일 것입니다. –

+0

코드에 몇 가지 주석을 달았습니다.하지만 본질적으로 이것은 잘못되었거나 어떻게 수정했는지에 대한 설명없이 덤프 된 코드 일뿐입니다. – kontur

관련 문제