3

I have been unable to figure out if there is a way to extract a zip into a specific directory with php. When using code such as

$zip->extractTo("files/");

it will extract the zip to the directory "files" and place all the files within a directory matching the name of the zip. I don't want the uploading party to be able to decide the name of the directory being uploaded to. For example if I upload a zip called "zip.pdf" containing "myimg.jpg" when I extract it it's location becomes:

files/zip/myimg.jpg

where as I want it to be

files/myimg.jpg

Anyway, I was wondering if there is a way to just have ZipArchive NOT create a new directory to house the unzipped contents or if I will have to loop through all the unzipped files and move them once the unzip has completed.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
rcooper102
  • 209
  • 1
  • 11

1 Answers1

2

The most safe way is to shuffle through zip contents and process each file individually. That is, unpack to unique temporary directory, then look at each file and decide. What if there is a clash of different users' files? Don't let this happen blindly.

spacediver
  • 1,483
  • 1
  • 11
  • 18
  • Its a really simple zip driven CMS for a client, the goal is just to have any new uploads completely override the previous set of files if there are conflicts. We are just trying to avoid forcing the client to use a specific zip filename. – rcooper102 Jul 19 '12 at 23:33