Created
November 12, 2020 20:30
-
-
Save anovsiradj/32047c665cb8d20ab04c26c26e32caec to your computer and use it in GitHub Desktop.
FTP provided by free hosting service is always slooow also zip-extraction is very broken. Lets just let PHP do the work.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* | |
* WARNING: DATA LOSS; (YOU HAVE BEEN WARNED) | |
* | |
* @version 20160124071141 | |
* @version 20201023144831 | |
* @author anovsiradj | |
* @author Touqeer Shafi | |
* @link https://superuser.com/a/1030589 | |
* | |
* create zip inside target directory (ex: /somedir/ => /somedir/somedir.zip) | |
* upload zip (ex: /public_html/somedir.zip) | |
* run this script from http(s). | |
* the result should be /public_html/somedir/ | |
* delete zip (ex: /public_html/somedir.zip) | |
* | |
*/ | |
$regex = '/\.zip$/'; | |
$file = scandir(__DIR__); | |
$file = array_filter($file, fn($i) => preg_match($regex, $i) == 1); | |
$file = current($file); | |
if (empty($file)) die('No ZIP'); | |
$path_zip = __DIR__ . "/${file}"; | |
$path_dir = preg_replace($regex, '', $file); | |
$path_dir = __DIR__ . "/${path_dir}"; | |
$zip = new ZipArchive; | |
if ($zip->open($path_zip)) { | |
$zip->extractTo($path_dir); | |
$zip->close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment