Deden Bangkit
Deden Bangkit

Reputation: 598

Problems when extract ZIP file in PHP

I'm trying to extract zip file to some folder in storage_path (I'm using laravel). But I don't know why they comes with .(dot)files when it extracted, also I want to extract them without creating another folder. Here's the code I'm using:

lines inside some public function:

$src = storage_path('application');
$dst = storage_path('tmp/'.time());
$zipfile = $request->file('splashicon');
$zipfile->move($dst, 'splashicon');
$this->splashIcon($dst.'/splashicon', $dst);

splashIcon function:

public function splashIcon($src, $dst)
{
    $zip = new ZipArchive();
    $x = $zip->open($src);  // open the zip file to extract
    if ($x === true) {
        $zip->extractTo($dst.'/www'); // place in the directory with same name
        $zip->close();
        unlink($src); //Deleting the Zipped file
    }
}

The current result is:

1494618313/www/name.files/thecontentsofzipfile

I have no idea where .(dot) and files came from, please explain what was happened to them.

And by the way, the correct result should be something like this:

1494618313/www/thecontentsofzipfile

Thank you,

Upvotes: 2

Views: 5469

Answers (1)

Bazgrim
Bazgrim

Reputation: 189

This is a laravel convention. The . means it's a subfolder/subfile within your directory. I'm not really sure how to get around it.

You might look into Zipper, which is an extraction helper for Laravel. I believe it has an exact match for extraction instead of using the typical Laravel syntax.

https://github.com/Chumper/Zipper

Upvotes: 1

Related Questions