Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set('display_errors',1); // enable php error display for easy trouble shooting
- error_reporting(E_ALL); // set error display to all
- DEFINE ('_BASEFOLDER_', 'folder');
- DEFINE ('_TMPFOLDER_','folder/_tmp');
- function clearTmpFolder() {
- if (!file_exists(_TMPFOLDER_)) {
- mkdir(_TMPFOLDER_);
- } else {
- foreach (GLOB(_TMPFOLDER_ . '/*') as $files) {
- if (!unlink($files)) {
- die('Unable to clear tmp folder. Please check folder permission');
- }
- }
- }
- }
- if (isset($_POST['folder'])) {
- if (!file_exists(_BASEFOLDER_)) {
- mkdir(_BASEFOLDER_);
- }
- if (isset($_FILES['project'])) {
- $file_path = _TMPFOLDER_ . '/temp.zip';
- clearTmpFolder();
- if (move_uploaded_file($_FILES['project']['tmp_name'], $file_path)) {
- $zip = new ZipArchive;
- if ($zip->open($file_path) === TRUE) {
- $newfolder = 'folder/' . $_POST['folder'] . '_'. microtime();
- mkdir($newfolder);
- $zip->extractTo($newfolder);
- $zip->close();
- clearTmpFolder();
- } else {
- echo 'Fail to open zip file. File may be corrupted';
- }
- }
- }
- }
- ?>
- <form action="" method="POST" enctype="multipart/form-data">
- <input type="file" name="project">
- <input type="hidden" name="folder" value="project">
- <input type="submit" name="submit" value="submit">
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement