Last active
March 12, 2019 06:57
-
-
Save mberizzo/9995be7fd591b9d60196b2f0bfc23010 to your computer and use it in GitHub Desktop.
PHP script that unzip file.zip
This file contains hidden or 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 | |
// When i have to upload multiple files in a shared hosting: | |
// 1. Compress your project and upload to your shared server | |
// 2. Visit url via shell (ex: "curl http://domain.com/unzip.php &") or any navigator | |
// Alternative step 2 (sometimes php throw timeout error): | |
// 1. Create a cronjob that visit unzip.php file (just one time) | |
error_reporting(E_ALL ^ E_STRICT); | |
ini_set('display_errors', 'On'); | |
$file = 'file.zip'; | |
// Get the absolute path to $file | |
$path = pathinfo(realpath($file), PATHINFO_DIRNAME); | |
$zip = new ZipArchive; | |
$res = $zip->open($file); | |
if ($res === TRUE) { | |
// Extract it to the path we determined above | |
$zip->extractTo($path); | |
$zip->close(); | |
echo "WOOT! $file extracted to $path"; | |
} else { | |
echo "Doh! I couldn't open $file"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Las horas de subida de FTP que me has ahorrado con esta magia 💋