게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
php로 zip파일 만들기 연습중인데 잘 안되네요 ㅠㅠ
게시물ID : programmer_15998짧은주소 복사하기
작성자 : DA-ZE
추천 : 0
조회수 : 794회
댓글수 : 4개
등록시간 : 2016/02/28 19:35:58
//index.php

<?php
    require_once "zipfile.php";

    $zipper = new Zipper;

    //$zipper->add('file/one.txt');
    $zipper->add(array('file/one.txt','file/two.txt','file/three.txt','file/four.txt'));

    $zipper->store('file/zipfile.zip');
?>



//zipfile.php


<?php
class Zipper
{
    private $_files = array(),
            $_zip;

    public function __construct()
    {
        $this->_zip = new Ziparchive;
    }

    public function add($input)
    {
        if(is_array($input))
        {
            //echo "it is array<br/>";
            $this->_files = array_merge($this->_files , $input);
        }else
        {
            //echo "it is not array<br/>";
            $this->_files[] = $input;
        }
    }

    public function store( $location = null )
    {
        if( count($this->_files) && $location )
        {
            foreach( $this->_files as $index => $file )
            {
                if( !file_exists($file) )
                {
                    unset( $this->_files[$index] );
                }
            }

            if( $this->_zip-> open( $location , file_exists($location) ) ? ZipArchive::OVERWRITE : ZipArchive::CREATE )
            {
                foreach( $this->_files as $file )
                {
                    $this->_zip->addFile($file,$file);
                }
                $this->_zip->close();
            }
        }
    }
}
?>

//error code

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in C:\Bitnami\wampstack-5.5.30-0\apache2\htdocs\zip_file\zipfile.php on line 41

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in C:\Bitnami\wampstack-5.5.30-0\apache2\htdocs\zip_file\zipfile.php on line 41

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in C:\Bitnami\wampstack-5.5.30-0\apache2\htdocs\zip_file\zipfile.php on line 41

Warning: ZipArchive::close(): Invalid or uninitialized Zip object in C:\Bitnami\wampstack-5.5.30-0\apache2\htdocs\zip_file\zipfile.php on line 43

유툽에서 영상보면서 따라하고있는데 존재하지않는 파일 배열에서 빼내는거까진 오류없이 잘 실행됬는데 addFile() 부터 막히네요 ㅠㅠ

php 넘나 어려운것...흑흑
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호