[473] | 1 | <?php |
---|
| 2 | |
---|
| 3 | define('VIOLET_APP_DIR', realpath(dirname(__FILE__).'/..')); |
---|
| 4 | |
---|
| 5 | class violetUtil { |
---|
| 6 | |
---|
| 7 | public static function getTempPath($dir = '', $create = false) { |
---|
| 8 | $tempPath = VIOLET_APP_DIR . '/Temp/' . $dir; |
---|
| 9 | if ($dir != '' && !file_exists($tempPath)) mkdir($tempPath, 0777, true);; |
---|
| 10 | return $tempPath; |
---|
| 11 | } |
---|
| 12 | |
---|
| 13 | public static function Unzip($zipFile, $destFolder) { |
---|
| 14 | self::execCmd("/usr/bin/unzip -o -d '$destFolder' '$zipFile'"); |
---|
| 15 | } |
---|
| 16 | |
---|
| 17 | public static function createZip($srcFolder, $zipFile) { |
---|
| 18 | chdir($srcFolder); |
---|
| 19 | self::execCmd("/usr/bin/zip -R '$zipFile' '*'"); |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | public static function execCmd($command) { |
---|
| 23 | $descriptorspec = array( |
---|
| 24 | 0 => array('pipe', 'r'), // stdin is a pipe that the child will read from |
---|
| 25 | 1 => array('pipe', 'w'), // stdout is a pipe that the child will write to |
---|
| 26 | ); |
---|
| 27 | $process = proc_open($command, $descriptorspec, $pipes); |
---|
| 28 | if (is_resource($process)) { |
---|
| 29 | while (!feof($pipes[1])) { |
---|
| 30 | $line = fgets($pipes[1], 1024); |
---|
| 31 | } |
---|
| 32 | fclose($pipes[1]); |
---|
| 33 | proc_close($process); |
---|
| 34 | } |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | public static function cleanDirectory($path) { |
---|
| 38 | foreach (scandir($path) as $dir) { |
---|
| 39 | if ($dir=='.' || $dir=='..') continue; |
---|
| 40 | $dname = $path.'/'.$dir; |
---|
| 41 | if (is_dir($dname)) self::cleanDirectory($dname); |
---|
| 42 | else if (is_file($dname)) unlink($dname); |
---|
| 43 | } |
---|
| 44 | rmdir($path); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | public static function copyAllFile($pattern, $src, $dest) { |
---|
| 48 | foreach (glob($src.$pattern) as $srcFileName) { |
---|
| 49 | $fileName = substr($srcFileName, strlen($src)); |
---|
| 50 | copy($srcFileName, $dest.$fileName); |
---|
| 51 | } |
---|
| 52 | } |
---|
| 53 | } |
---|