24 November 2009

PHP: How to upload ZIP, check if file exists within it & extract to the server

I had to do this today for a job. It took far longer than it should have. The resources online are minimal and php.net does not mention any keywords like file_exists on manual for the function needed to do this. so...

Here is the best way to check if an uploaded zip archive contains a certain file and if so, extract the entire contents to a directory on your server:

Please see right hand panel before copying>

$zipFile=$_FILES["your file field name here"];

if($zipFile["error"] == UPLOAD_ERR_OK){
        $zip = new ZipArchive;
        $res = $zip->open($zipFile["tmp_name"]);
        if ($res === TRUE) {
                //put extra functions here if you want
                echo "ERROR: Uploaded zip archive is missing a required file!";
            echo "ERROR: Could not open uloaded zip archive";
        echo "ERROR: Uploaded file is not a zip archive"
    echo  "ERROR: The upload was not successful";


Anonymous said...

No you did not help me!

Unknown said...

coach outlet
michael kors handbags
longchamp bags
adidas nmd
michael kors outlet online
polo ralph lauren outlet online
cheap mlb jerseys
coach factory outlet
cheap uggs
cheap uggs

asdasd said...

pg เว็บสล็อต สมัคร ฟรี ฟรี สมัคร PG SLOT กับเว็บไซต์ของเรา รับโปรโมชั่นดีๆที่หาไม่ได้จากที่อื่น พร้อมทั้งระบบการสมัครสมาชิกที่รองรับให้ท่านสามารถสมัครได้อย่างรวดเร็ว ผ่านทางระบบออโต้

Post a Comment

Cron Design Studio: Dublin based web design & software development