2012-07-04 2 views
0

나는 코드를업로드 된 zip 파일을 압축 해제하는 방법은 무엇입니까?

function do_upload() 
{ 
    $name=time(); 
    $config['upload_path'] = './uploadedModules/'; 
    $config['allowed_types'] = 'zip|rar'; 
    $this->load->library('upload', $config); 

    if (! $this->upload->do_upload()) 
    { 
     $error = array('error' => $this->upload->display_errors()); 

     $this->load->view('upload_view', $error); 
    } 
    else 
    { 
     $data = array('upload_data' => $this->upload->data()); 

     $this->load->library('unzip'); 

    // Optional: Only take out these files, anything else is ignored 
    $this->unzip->allow(array('css', 'js', 'png', 'gif', 'jpeg', 'jpg', 'tpl', 'html', 'swf')); 

    $this->unzip->extract('./uploadedModules/'.$data['upload_data']['file_name'], './application/modules/'); 



     $pieces = explode(".", $data['upload_data']['file_name']); 
     $title=$pieces[0]; 
     $status=1; 
     $core=0; 
     $this->addons_model->insertNewModule($title,$status,$core); 

    } 
} 

을 다음과 같이 프레임 워크를 CodeIgniter를 사용하여 압축 파일을 업로드하려고하지만 큰 문제는 추출 함수가 호출 될 때, 그것은 우편 번호를 추출하는 것입니다하지만 결과는 빈 폴더입니다. 이 문제를 극복 할 수있는 방법이 있습니까?

+0

가 [zip_open]의 설명서를 참조하십시오 (http://www.php.net/manual/en/function.zip-open.php) 방법 –

답변

0

이 시도 :

<?php 
exec('unzip filename.zip'); 
?> 
0

흠 .. 난 당신이 잘못된 업로드 한 zip 파일의 경로 또는 목적지 경로 ('./application/modules/')를 올바르지 설정 생각합니다.

이 시도 : - 그것은 업로드 된 파일의 실제 경로입니다 있는지 확인>$ 데이터 [ 'upload_data'] [ 'full_path'],

$this->unzip->extract($data['upload_data']['full_path'], './application/modules/'); 

을 나는 이것을 사용합니다.

는 데 도움이 : 난 당신이 관찰 뒤편 몇 분에 직면

0

같은 문제는 신중하게 이 zip 파일을 복사하십시오 발견하고 그 후 프로그램 자체 파일 (.PHP)를 포함 폴더에 붙여 넣기 희망 당신

나는 파일이 temp 폴더에 저장되지 않는다고 생각한다.

if(preg_match("/.(zip)$/i", $fileName)) 
{ 
$moveResult= move_uploaded_file($fileTmpLoc, $fileName); 

if($moveResult == true) 
{ 
    $zip = new ZipArchive; 

    $res = $zip->open($fileName); 

    if($res==TRUE) 
     { 
      $zip->extractTo($path.$fileName); 

      echo "<pre>"; 
      print_r($zip); 


      $zip->close(); 
     } else { 
     echo 'failed'; 
     } 

} 

unlink($fileName); // Remove the uploaded file from the PHP temp folder 
//exit(); 
}` 
+1

당신이 당신의 대답을 완료하시기 바랍니다 수 - 중간 문장으로 글쓰기를 그만 둔 것 같습니다 ... – Spontifixus

3
$zip = new ZipArchive; 

    $res = $zip->open($fileName); 

    if($res==TRUE) 
     { 
      $zip->extractTo($path.$fileName); 

      echo "<pre>"; 
      print_r($zip);//to get the file type 


      $zip->close(); 
0
class Upload extends CI_Controller { 
function __construct(){ 
    parent::__construct(); 
    // load ci's Form and Url Helpers 
    $this->load->helper(array('form', 'url')); 
} 
function index(){ 
    $this->load->view('upload_form_view', array('error' => ' ')); 
} 
function file_upload(){ 
    $config['upload_path'] = './uploads/'; 
    $config['allowed_types'] = 'zip'; 
    $config['max_size'] = ''; 
    $this->load->library('upload', $config); 
    if (! $this->upload->do_upload()){ 
    $error = array('error' => $this->upload->display_errors()); 
    $this->load->view('upload_form_view', $error); 
    }else{ 
    $data = array('upload_data' => $this->upload->data()); 
    $zip = new ZipArchive; 
    $file = $data['upload_data']['full_path']; 
    chmod($file,0777); 
    if ($zip->open($file) === TRUE) { 
      $zip->extractTo('./uploads/'); 
      $zip->close(); 
      echo 'ok'; 
    } else { 
      echo 'failed'; 
    } 
    $this->load->view('upload_success_view', $data); 
    } 
    } 
} 
관련 문제