PHP ZipArchive extractTo problems

So, I'm trying to create a bulk upload function, when a user can upload a single ZIP file containing a bunch of PDF files, which will then be processed and saved on the server, etc.

While I have it ...

$serverpath = $_SERVER['DOCUMENT_ROOT'];

if(array_key_exists('bulk_filename', $_FILES)){
    if ($_FILES['bulk_filename']['error'] === UPLOAD_ERR_OK) {

        $file_name = $_FILES['bulk_filename']['name'];
        $new_zip_file = $serverpath . '/customerdata/tmp_invoices/' . $file_name;
        move_uploaded_file($_FILES['bulk_filename']['tmp_name'], $new_zip_file);

        // zip file is coming in as "-rw-r--r--" and should be "-rwxr-xr-x"
        exec('chmod -R 755 ' . $serverpath . '/customerdata/tmp_invoices/' . $file_name);

        // Extract the files from zip
        $zip = new ZipArchive;
        $res = $zip->open($new_zip_file, ZipArchive::OVERWRITE);
        if ($res !== true) {
            die("Cannot open {$new_zip_file} for writing!");
        }
        else{
            $res = $zip->extractTo($serverpath . '/customerdata/tmp_invoices/');
            $zip->close();

            ////////////////////////////////////////////
            // I ALWAYS REACH THIS CODE BLOCK
            // and $res always equals 1/true
            ////////////////////////////////////////////
        }
    } else
        die("Upload failed with error code " . $_FILES['bulk_filename']['error']);
}

The problem that I see is that even if the function extractToreturns as successful extraction (1), I don’t see the files that were apparently extracted ?!

I always see the file Archive.zip, so I know that it loads correctly ...

-rwxr-xr-x 1 nginx nginx 68512374 May  4 12:39 Archive.zip

Any ideas on what I am doing wrong?!: - /

ENVIRONMENT: Centos 6 works with PHP 5.3.3

UPDATE

Below (with a full path) it does not produce any errors, it just does not work out any extraction ?!

$zip->extractTo($serverpath . '/customerdata/tmp_invoices/');

( ) Warning: ZipArchive::extractTo(): Permission denied in...?!

$zip->extractTo('/customerdata/tmp_invoices/'); 

+4
1

, - ...

"" , :

: $zip->open($new_zip_file, ZipArchive::OVERWRITE)

: $zip->open($new_zip_file, ZipArchive::CREATE)

php.net

ZipArchive::CREATE (integer)

, .

ZipArchive::OVERWRITE (integer)

, , .

+1

All Articles