예제 #1
0
파일: text.php 프로젝트: raul21/yaCMS
 * $result['files'] - an array containing all the text files from the 'secret'
 * folder
 * $result['content'] - string that holds the content of the chosen file
 * $result['msg'] - string that holds metadatas about the secret folder, the
 * file or the upload itself
 * TXT_ERR_PASS - will be returned when passphrase(secret) is incorrect
 * TXT_ERR_READ - returned when file_get_contents() fails
 * TXT_ERR_WRITE - returned if there is an error on writing the new contents to the
 * file
 */
$result = array('files' => NULL, 'contents' => NULL, 'msg' => NULL);
if (isset($_POST['edit'])) {
    if (isset($_POST['secret']) && !empty($_POST['secret'])) {
        $secret = strip_tags($_POST['secret']);
        if (is_dir(UPLOADS_ROOT . $secret)) {
            $result['files'] = find_files_by_mime(UPLOADS_ROOT . $secret, 'text', FALSE);
            foreach ($result['files'] as $key => $file) {
                $result['files'][$key] = strip_tags(substr($file, strrpos($file, '/') + 1));
            }
            $result['msg'] = $secret;
        } else {
            //passphrase incorrect(inexistent directory)
            return TXT_ERR_PASS;
        }
    } elseif (isset($_POST['filelist'])) {
        $file = UPLOADS_ROOT . $_POST['sec'] . DIRECTORY_SEPARATOR . $_POST['filelist'];
        $result['contents'] = file_get_contents($file);
        if (FALSE == $result['contents']) {
            return TXT_ERR_READ;
        }
        $result['msg'] = $_POST['sec'] . DIRECTORY_SEPARATOR . $_POST['filelist'];
예제 #2
0
파일: gallery.php 프로젝트: raul21/yaCMS
<?php

/**
 * BL for the gallery script
 */
$result = NULL;
if (isset($_POST['submit'])) {
    if (isset($_POST['dir']) && !empty($_POST['dir'])) {
        $dir_name = $_POST['dir'];
        $dir = UPLOADS_ROOT . $dir_name;
        if (is_dir($dir)) {
            $result = find_files_by_mime($dir, 'image', FALSE);
            if (!empty($result)) {
                return $result;
            } else {
                return G_ERR_NO_IMAGES;
            }
        } else {
            return G_ERR_IS_DIR;
        }
    } else {
        return G_ERR_NO_DIR;
    }
}
return G_OK;
/* vim: set ts=4 sw=4 tw=80 sts=4 fdm=marker nowrap et :*/
예제 #3
0
파일: functions.php 프로젝트: raul21/yaCMS
/**
 * Searches recursively in the path provided by $path the files which have the
 * MIME type set to $mime
 *
 * @param string $path path to a directory
 * @param string $mime MIME type to be matched
 * @param bool $recursive if TRUE searches recursively
 *
 * @return array $files containing the path to the files
 */
function find_files_by_mime($path, $mime, $recursive = TRUE)
{
    $files = array();
    $finfo = finfo_open(FILEINFO_MIME_TYPE);
    if (DIRECTORY_SEPARATOR != substr($path, -1)) {
        $path .= DIRECTORY_SEPARATOR;
    }
    if (is_dir($path)) {
        $d = opendir($path);
        while ($entry = readdir($d)) {
            $mime_type = finfo_file($finfo, $path . $entry);
            if ("." != $entry && ".." != $entry) {
                if (is_dir($path . $entry) && $recursive) {
                    $files = array_unique(array_merge(find_files_by_mime($path . $entry, $mime), $files));
                } elseif (FALSE !== stristr($mime_type, $mime)) {
                    $files[] = $path . $entry;
                }
            }
        }
        closedir($d);
    }
    return $files;
}