0

I'm building a site where I'd like to be able to upload a small zip file of images using a form and extracting using PHP, but I have no idea how to do this or where to begin looking for a solution.

I have this code:

$photo_path = "photos/$year/";
$zip_path = "sets/$year/";

$photo = $_FILES["photo"]["name"];
$gallery = $_FILES["gallery"]["name"];

move_uploaded_file($_FILES["photo"]["tmp_name"],"$photo_path" . $id . ".jpg"); //Adds Photo To $photo_path

move_uploaded_file($_FILES["gallery"]["tmp_name"],"$zip_path" . $id . ".zip"); // Adds Zip File To $zip_path

How could I best get the zip file that I upload to extract using PHP?

  • Possible duplicate of [Unzip a file with php](http://stackoverflow.com/questions/8889025/unzip-a-file-with-php) – Thernys May 05 '16 at 16:22
  • I tried something like that but got `Fatal error: Class 'ZipArchive' not found in C:...`! ( Localhost ) – Unhappy Blogger May 05 '16 at 16:24
  • Try `new \ZipArchive;`, the backslash indicates that you are accessing the global namespace, and may be required depending on your environment and circumstance. – Thernys May 05 '16 at 16:28
  • That causes a `Warning: Unexpected character in input: '\' (ASCII=92) state=1` + The original error! – Unhappy Blogger May 05 '16 at 16:30
  • You would need to install/enable the ZipArchive php extension (http://php.net/manual/en/zip.installation.php). This might also be worth a try https://github.com/alchemy-fr/Zippy – martindilling May 05 '16 at 16:32
  • @martindilling - I've enabled it in ini but I'm still getting the same original error – Unhappy Blogger May 05 '16 at 16:41

0 Answers0