Nevin Thomas
Nevin Thomas

Reputation: 826

ZipArchive extractTo() not working with URL

I am trying to extract a ZipArchive to 'http://localhost/MODULES/ZIP_RAR_MANAGER/'.

No errors are shown, and I get the message Zip File Opened.

Why are the files not being correctly extracted from the zip archive?

$zip = new ZipArchive;

if ($zip->open('../test.zip')) 
{
    echo 'ZIP FILE OPENED...<br/>';

    if ($zip->extractTo('http://localhost/MODULES/ZIP_RAR_MANAGER/'))
    {
        echo 'ZIP FILE EXTRACTED';
    }

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

Upvotes: 0

Views: 1139

Answers (1)

Ivan Hušnjak
Ivan Hušnjak

Reputation: 3503

You are trying to extract it to non-existent folder http://localhost/MODULES/ZIP_RAR_MANAGER/. You cannot use url as a folder/file path.

You should use:

if ($zip->extractTo($_SERVER['DOCUMENT_ROOT'] . '/MODULES/ZIP_RAR_MANAGER/') {
...
}

Upvotes: 1

Related Questions