Skip to content

Instantly share code, notes, and snippets.

@anovsiradj
Created November 12, 2020 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anovsiradj/32047c665cb8d20ab04c26c26e32caec to your computer and use it in GitHub Desktop.
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.
<?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