Example #1
0
function listDirs($dir, $root)
{
    $dir_and_files = [];
    $dir_requote = '/^' . preg_quote($root) . '/';
    print $dir_requote . PHP_EOL;
    if (is_dir($dir)) {
        if ($dh = opendir($dir)) {
            while (($file = readdir($dh)) !== false) {
                if (is_dir($dir . "/" . $file) && $file != "." && $file != "..") {
                    //is dir
                    $subdir = $dir . "/" . $file;
                    $relative_dir = trim(preg_replace($dir_requote, "", $subdir, 1), '/');
                    if ($relative_dir) {
                        print "add dir: {$relative_dir}" . PHP_EOL;
                        $dir_and_files[] = ['dir' => $relative_dir];
                    }
                    //                  print ("read dir: $dir $file".PHP_EOL);
                    $dir_and_files = @array_merge($dir_and_files, @listDirs($dir . "/" . $file, $root));
                } else {
                    //is file
                    if ($file != "." && $file != "..") {
                        $relative_dir = trim(preg_replace($dir_requote, "", $dir, 1), '/');
                        $dir_and_files[] = ['dir' => $relative_dir, 'file' => $file];
                    }
                }
            }
            closedir($dh);
        }
    }
    return $dir_and_files;
}
function generate($input_dir, $namespace_mappings, $output_dir)
{
    $rel_dir_and_files = listDirs($input_dir, $input_dir);
    //    print_r($namespace_mappings);
    //    print_r($rel_dir_and_files);
    foreach ($rel_dir_and_files as $rel_dir_and_file) {
        $rel_dir = $rel_dir_and_file['dir'];
        if (array_key_exists($rel_dir, $namespace_mappings)) {
            $namespace = $namespace_mappings[$rel_dir];
        } else {
            //              $namespace = ucfirst($rel_dir);
            $namespace = join('\\', array_map(function ($path) {
                return ucfirst($path);
            }, explode('/', $rel_dir)));
        }
        $dir = str_replace('\\', '/', $namespace);
        print "{$namespace} ;;" . PHP_EOL;
        print $rel_dir . ' => ' . $dir . PHP_EOL;
        if (array_key_exists('file', $rel_dir_and_file)) {
            $file = $rel_dir_and_file['file'];
            //            print ('make dir if not exists:' . $output_dir . '/' . $dir . PHP_EOL);
            //            mkdirIfNotExists($output_dir . '/' . $dir);
            print "processing {$input_dir}|{$rel_dir}|{$file}  => {$namespace}" . PHP_EOL;
            appendNamespace($input_dir . '/' . $rel_dir . '/' . $file, $namespace, $output_dir . '/' . $dir . '/' . $file);
        } else {
            print 'make dir:' . $output_dir . '/' . $dir . PHP_EOL;
            mkdirIfNotExists($output_dir . '/' . $dir);
        }
    }
}
Example #3
0
function listDirs($DirPath)
{
    if ($DirPath == "") {
        $DirPath = './';
    }
    // In directories gaan kijken
    if ($handle = opendir($DirPath)) {
        while ($node = readdir($handle)) {
            $nodebase = basename($node);
            if ($nodebase != "." && $nodebase != "..") {
                // Directory gevonden? (niet web/thumb)
                if (is_dir($DirPath . $node) && $node != 'web' && $node != 'thumb') {
                    // Directory ingaan en opnieuw zoeken...
                    $nPath = $DirPath . $node . "/";
                    listDirs("{$nPath}");
                    // Naam van directory weergeven
                    echo "<directory dir='{$nPath}' ";
                    // Nakijken of er thumb en web directories bestaan
                    if (file_exists($DirPath . $node . "/thumb") && file_exists($DirPath . $node . "/web")) {
                        echo "publicatie='1'>";
                        findJPG("{$nPath}");
                        echo "</directory>";
                    } else {
                        echo "publicatie='0'>";
                        //findJPG("$nPath");
                        echo "</directory>";
                    }
                }
            }
        }
    }
}
Example #4
0
File: ajax.php Project: vobinh/PHP
        $name = urldecode($_POST['newname']);
        $reply['isSuccess'] = createDir($path, $name);
        break;
    case 'deleteFolder':
        $path = urldecode($_POST['dir']);
        $reply['isDelete'] = deleteDir($path);
        break;
    case 'deleteFiles':
        $dir = urldecode($_POST['dir']);
        $files = urldecode($_POST['files']);
        $files = explode('::', $files);
        deleteFiles($dir, $files);
        $reply['files'] = listFiles($dir);
        break;
    case 'getFiles':
        $reply['files'] = listFiles($dir);
        break;
    case 'getDirs':
        $reply['dirs'] = listDirs($dir);
        break;
    default:
        exit;
        break;
}
if (isset($_GET['noJson'])) {
    echo '<pre>';
    print_r($reply);
    echo '</pre>';
    exit;
}
exit(json_encode($reply));
Example #5
0
 function getlanguages($value)
 {
     $selectLanguages = listDirs('languages/' . $value . '/');
     if (count($selectLanguages) < 1) {
         $selectLanguages = listDirs('languages/default/');
     }
     if (count($selectLanguages) < 1) {
         $selectLanguages = listDirs('languages/');
     }
     return $selectLanguages;
 }
<?php

/**
 * Created by PhpStorm.
 * User: wu
 * Date: 2016/3/1
 * Time: 17:23
 */
require "utils.php";
$input_dir = realpath(__DIR__ . "/../src/Alipay/OpenApi/aop/request");
$output_file = realpath(__DIR__ . "/../src/Alipay/OpenApi") . '/Requests.php';
print $output_file;
$dirs = listDirs($input_dir, $input_dir);
/*  template
<?php
//// generated automatically
namespace Alipay\OpenApi;
class Requests
{
    const AlipayAcquireCancelRequest = 'AlipayAcquireCancelRequest';
}
*/
$out = fopen($output_file, 'w') or die('???');
$head = "<?php\n//// automatic generated\nnamespace Alipay\\OpenApi;\nclass Requests\n{\n";
$tail = "\n};";
fwrite($out, $head);
foreach ($dirs as $rel_dir) {
    //    print ( $rel_dir['file'] .PHP_EOL);
    $filename = $rel_dir['file'];
    $className = pathinfo($filename, PATHINFO_FILENAME);
    fwrite($out, "   const {$className} = '{$className}';" . PHP_EOL);
Example #7
0
File: Ajax.php Project: sereg/mebel
 public function index()
 {
     //die();
     header('Expires: Sun, 13 Sep 2009 00:00:00 GMT');
     header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
     header('Cache-Control: no-store, no-cache, must-revalidate');
     header('Cache-Control: post-check=0, pre-check=0', false);
     header('Pragma: no-cache');
     //header('Content-Type: text/json; charset=utf-8');
     define('DEV', false);
     if (DEV) {
         error_reporting(E_ALL);
         ini_set('display_errors', 'on');
         ini_set('display_startup_errors', 'on');
     } else {
         error_reporting(0);
         ini_set('display_errors', 'off');
         ini_set('display_startup_errors', 'off');
     }
     //if (!isset($_SESSION['admin'])) {exit;}			// Do not forget to add your user authorization
     define('DIR_SEP', '/');
     mb_internal_encoding('utf-8');
     date_default_timezone_set('Europe/Moscow');
     $cfg['url'] = 'files/site/upload';
     $cfg['root'] = $_SERVER['DOCUMENT_ROOT'] . DIR_SEP . $cfg['url'];
     // http://www.yousite.com/upload/		absolute path
     $cfg['quickdir'] = '';
     //$cfg['quickdir'] = 'quick-folder';		// for CKEditor
     $cfg['lang'] = 'ru';
     $cfg['thumb']['width'] = 150;
     $cfg['thumb']['height'] = 120;
     $cfg['thumb']['quality'] = 80;
     $cfg['thumb']['cut'] = true;
     $cfg['thumb']['auto'] = true;
     $cfg['thumb']['dir'] = '_thumb';
     $cfg['thumb']['date'] = "j.m.Y, H:i";
     $cfg['hide']['file'] = array('.htaccess');
     $cfg['hide']['folder'] = array('.', '..', $cfg['thumb']['dir'], '.svn', '.cvs');
     $cfg['chmod']['file'] = 0777;
     $cfg['chmod']['folder'] = 0777;
     $cfg['deny'] = array('file' => array('php', 'php3', 'php4', 'php5', 'phtml', 'asp', 'aspx', 'ascx', 'jsp', 'cfm', 'cfc', 'pl', 'bat', 'exe', 'dll', 'reg', 'cgi'), 'flash' => array(), 'image' => array(), 'media' => array(), 'folder' => array($cfg['url'] . DIR_SEP . 'file', $cfg['url'] . DIR_SEP . 'flash', $cfg['url'] . DIR_SEP . 'image', $cfg['url'] . DIR_SEP . 'media'));
     $cfg['allow'] = array('file' => array('7z', 'aiff', 'asf', 'avi', 'bmp', 'csv', 'doc', 'fla', 'flv', 'gif', 'gz', 'gzip', 'jpeg', 'jpg', 'mid', 'mov', 'mp3', 'mp4', 'mpc', 'mpeg', 'mpg', 'ods', 'odt', 'pdf', 'png', 'ppt', 'pxd', 'qt', 'ram', 'rar', 'rm', 'rmi', 'rmvb', 'rtf', 'sdc', 'sitd', 'swf', 'sxc', 'sxw', 'tar', 'tgz', 'tif', 'tiff', 'txt', 'vsd', 'wav', 'wma', 'wmv', 'xls', 'xml', 'zip'), 'flash' => array('swf', 'flv'), 'image' => array('jpg', 'jpeg', 'gif', 'png', 'bmp'), 'media' => array('aiff', 'asf', 'avi', 'bmp', 'fla', 'flv', 'gif', 'jpeg', 'jpg', 'mid', 'mov', 'mp3', 'mp4', 'mpc', 'mpeg', 'mpg', 'png', 'qt', 'ram', 'rm', 'rmi', 'rmvb', 'swf', 'tif', 'tiff', 'wav', 'wma', 'wmv'));
     $cfg['nameRegAllow'] = '/^[a-z0-9-_#~\\$%()\\[\\]&=]+/i';
     //	------------------
     $cfg['url'] = trim($cfg['url'], '/\\');
     $cfg['root'] = rtrim($cfg['root'], '/\\') . DIR_SEP;
     $dir = isset($_POST['dir']) ? urldecode($_POST['dir']) : '';
     $dir = trim($dir, '/\\') . DIR_SEP;
     $rpath = str_replace('\\', DIR_SEP, realpath($cfg['root'] . $dir) . DIR_SEP);
     if (false === strpos($rpath, str_replace('\\', DIR_SEP, $dir))) {
         $dir = '';
     }
     $mode = isset($_GET['mode']) ? $_GET['mode'] : 'getDirs';
     $cfg['type'] = isset($_POST['type']) ? $_POST['type'] : (isset($_GET['type']) && 'QuickUpload' == $mode ? $_GET['type'] : 'file');
     $cfg['sort'] = isset($_POST['sort']) ? $_POST['sort'] : 'name';
     $cfg['type'] = strtolower($cfg['type']);
     $reply = array('dirs' => array(), 'files' => array());
     //	------------------
     require_once BASE . '/files/site/all/AjexFileManager/ajax/php/lib.php';
     echo "echo";
     die;
     switch ($mode) {
         case 'cfg':
             $rootDir = listDirs('');
             $children = array();
             for ($i = -1, $iCount = count($rootDir); ++$i < $iCount;) {
                 $children[] = (object) $rootDir[$i];
             }
             $reply['config'] = array('lang' => $cfg['lang'], 'type' => $cfg['type'], 'url' => '/' . $cfg['url'] . '/', 'thumb' => $cfg['thumb']['dir'], 'thumbWidth' => $cfg['thumb']['width'], 'thumbHeight' => $cfg['thumb']['height'], 'maxUpload' => ini_get('upload_max_filesize'), 'allow' => implode('|', $cfg['allow'][$cfg['type']]), 'children' => $children);
             break;
         case 'renameFile':
             $file = trim(urldecode($_POST['oldname']), '/\\.');
             $name = urldecode($_POST['newname']);
             if ($file != $name && preg_match($cfg['nameRegAllow'], $name) && file_exists($cfg['root']) . $dir . $file) {
                 if (file_exists($_thumb = $cfg['root'] . $cfg['thumb']['dir'] . DIR_SEP . $dir . DIR_SEP . $file)) {
                     unlink($_thumb);
                 }
                 if (file_exists($cfg['root'] . $dir . $name)) {
                     $name = getFreeFileName($name, $cfg['root'] . $dir);
                 }
                 if (false !== strpos($name, '.')) {
                     $ext = substr($name, strrpos($name, '.') + 1);
                     if (in_array($ext, $cfg['allow']['image'])) {
                         rename($cfg['root'] . $dir . $file, $cfg['root'] . $dir . $name);
                     }
                 }
             }
             $reply['files'] = listFiles($dir);
             break;
         case 'createFolder':
             $path = trim(urldecode($_POST['oldname']), '/\\.');
             $name = urldecode($_POST['newname']);
             $reply['isSuccess'] = false;
             if (preg_match($cfg['nameRegAllow'], $name)) {
                 if (!file_exists($cfg['root'] . $path . DIR_SEP . $name)) {
                     $reply['isSuccess'] = mkdir($cfg['root'] . $path . DIR_SEP . $name, $cfg['chmod']['folder']);
                 } else {
                     $reply['isSuccess'] = 'exist';
                 }
             }
             break;
         case 'renameFolder':
             $folder = urldecode($_POST['oldname']);
             $name = urldecode($_POST['newname']);
             $folder = trim($folder, '/\\.');
             $reply['isSuccess'] = false;
             if (!empty($folder) && $cfg['url'] != $folder && $folder != $name && !in_array($cfg['url'] . DIR_SEP . $folder, $cfg['deny']['folder']) && preg_match($cfg['nameRegAllow'], $name) && is_dir($cfg['root']) . $folder) {
                 $reply['isSuccess'] = rename($cfg['root'] . $folder, $cfg['root'] . substr($folder, 0, strrpos($folder, '/')) . DIR_SEP . $name);
             }
             break;
         case 'deleteFolder':
             $reply['isDelete'] = false;
             $folder = trim($dir, '/\\');
             if (!empty($folder) && $cfg['url'] != $folder && !in_array($cfg['url'] . DIR_SEP . $folder, $cfg['deny']['folder'])) {
                 deleteDir($cfg['root'] . $cfg['thumb']['dir'] . DIR_SEP . $folder);
                 $reply['isDelete'] = deleteDir($cfg['root'] . $folder);
             }
             break;
         case 'uploads':
             $reply['downloaded'] = array();
             $width = isset($_POST['resizeWidth']) ? intval($_POST['resizeWidth']) : 0;
             $height = isset($_POST['resizeHeight']) ? intval($_POST['resizeHeight']) : 0;
             $key = 'uploadFiles';
             if (!empty($dir) && '/' != $dir && !empty($_FILES[$key])) {
                 for ($i = -1, $iCount = count($_FILES[$key]['name']); ++$i < $iCount;) {
                     $ext = substr($_FILES[$key]['name'][$i], strrpos($_FILES[$key]['name'][$i], '.') + 1);
                     if (!in_array($ext, $cfg['deny'][$cfg['type']]) && in_array($ext, $cfg['allow'][$cfg['type']])) {
                         $freeName = getFreeFileName($_FILES[$key]['name'][$i], $cfg['root'] . $dir);
                         if (in_array($ext, $cfg['allow']['image'])) {
                             if ($width || $height) {
                                 create_thumbnail($_FILES[$key]['tmp_name'][$i], $cfg['root'] . $dir . $freeName, $width, $height, 100, false, true);
                                 chmod($cfg['root'] . $dir . $freeName, $cfg['chmod']['file']);
                             } else {
                                 if (move_uploaded_file($_FILES[$key]['tmp_name'][$i], $cfg['root'] . $dir . $freeName)) {
                                     chmod($cfg['root'] . $dir . $freeName, $cfg['chmod']['file']);
                                     if ($cfg['thumb']['auto']) {
                                         create_thumbnail($cfg['root'] . $dir . $freeName, $cfg['root'] . $cfg['thumb']['dir'] . DIR_SEP . $dir . DIR_SEP . $freeName);
                                         chmod($cfg['root'] . $cfg['thumb']['dir'] . DIR_SEP . $dir . DIR_SEP . $freeName, $cfg['chmod']['file']);
                                     }
                                     $reply['downloaded'][] = array(true, $freeName);
                                 } else {
                                     $reply['downloaded'][] = array(false, $freeName);
                                 }
                             }
                         } else {
                             if (move_uploaded_file($_FILES[$key]['tmp_name'][$i], $cfg['root'] . $dir . $freeName)) {
                                 chmod($cfg['root'] . $dir . $freeName, $cfg['chmod']['file']);
                                 $reply['downloaded'][] = array(true, $freeName);
                             } else {
                                 $reply['downloaded'][] = array(false, $freeName);
                             }
                         }
                     } else {
                         $reply['downloaded'][] = array(false, $_FILES[$key]['name'][$i]);
                     }
                 }
             }
             break;
         case 'QuickUpload':
             switch ($cfg['type']) {
                 case 'file':
                 case 'flash':
                 case 'image':
                 case 'media':
                     $dir = $cfg['type'];
                     break;
                 default:
                     exit;
                     //	exit	for not supported type
                     break;
             }
             if (!is_dir($toDir = $cfg['root'] . $dir . DIR_SEP . $cfg['quickdir'])) {
                 mkdirs($toDir, $cfg['chmod']['folder']);
             }
             if (0 == $_FILES['upload']['error']) {
                 $fileName = getFreeFileName($_FILES['upload']['name'], $toDir);
                 $ext = substr($fileName, strrpos($fileName, '.') + 1);
                 $ext = strtolower($ext);
                 if (!in_array($ext, $cfg['deny'][$cfg['type']]) && in_array($ext, $cfg['allow'][$cfg['type']]) && move_uploaded_file($_FILES['upload']['tmp_name'], $toDir . DIR_SEP . $fileName)) {
                     $funcNum = isset($_GET['CKEditorFuncNum']) ? intval($_GET['CKEditorFuncNum']) : 2;
                     $result = "<script type=\"text/javascript\">window.parent.CKEDITOR.tools.callFunction(" . $funcNum . ", '/" . $cfg['url'] . '/' . $dir . '/' . (empty($cfg['quickdir']) ? '' : trim($cfg['quickdir'], '/\\') . '/') . $fileName . "', '');</script>";
                 }
             }
             exit($result);
             break;
         case 'deleteFiles':
             $files = urldecode($_POST['files']);
             $files = explode('::', $files);
             for ($i = -1, $iCount = count($files); ++$i < $iCount;) {
                 unlink($cfg['root'] . $dir . $files[$i]);
                 file_exists($_thumb = $cfg['root'] . $cfg['thumb']['dir'] . DIR_SEP . $dir . DIR_SEP . $files[$i]) ? unlink($_thumb) : null;
             }
             $reply['files'] = listFiles($dir);
             break;
         case 'getFiles':
             $reply['files'] = listFiles($dir);
             break;
         case 'getDirs':
             $reply['dirs'] = listDirs($dir);
             break;
         default:
             exit;
             break;
     }
     if (isset($_GET['noJson'])) {
         echo '<pre>';
         print_r($reply);
         echo '</pre>';
         exit;
     }
     exit(json_encode($reply));
 }
Example #8
0
function doList()
{
    global $dirs;
    $exts = array("gif", "jpg", "jpeg", "png");
    // initialize context
    $nodes = 0;
    $current = count($dirs) + 1;
    // emit the HTML
    echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n";
    dirTag(TEXT_ROOT, "", $nodes++, ICON_OPENED);
    // for ALL Directories in the Path ...
    foreach ($dirs as $dir) {
        // ... if Directory is exists ...
        if (strlen($dir) > 0) {
            // ... emit the HTML
            dirTag($dir, "", $nodes++, ICON_OPENED, $nodes != $current);
        }
    }
    // list Directories and emit the HTML
    $list = listDirs();
    @array_walk($list, dirTag, $nodes);
    // if BITMAP support is desired ...
    if (SUPPORT_BITMAP) {
        // ... include BMP extensions
        $exts[] = "bmp";
    }
    // if METAFILE support is desired ...
    if (SUPPORT_METAFILE) {
        // ... include WMF extensions
        $exts[] = "wmf";
    }
    // list Image files and emit the HTML
    $list = listFiles($exts);
    @array_walk($list, fileTag, $nodes);
    // emit the HTML
    echo "</table>\n";
}