Skip to content

Instantly share code, notes, and snippets.

@jentanbernardus
Created August 1, 2013 05:27
Show Gist options
  • Save jentanbernardus/6128609 to your computer and use it in GitHub Desktop.
Save jentanbernardus/6128609 to your computer and use it in GitHub Desktop.
Unzip an uploaded file using php

Unzip an uploaded file using php


If you dont have shell access to your server and need to unzip a file on your php server you can use this script. It basically extracts the zip file into the directory you specify. Make sure the directory you want to extract it to has write permissions.

<?php
$zip = new ZipArchive;
$res = $zip->open('my_zip_file.zip');
if ($res === TRUE) {
$zip->extractTo('my_extract_to_dir/');
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment