コード例 #1
0
function getFileName($dir)
{
    global $fix_utf8, $exclude_directories, $sort_files_by_date;
    $sort_by_date = $sort_files_by_date;
    if (!isset($_GET['index'])) {
        return '';
    }
    $index = parseInputParameter($_GET['index']);
    // All files are sorted in the array myFiles
    $dirhandle = opendir($dir);
    $myFiles = array();
    while (($file = readdir($dirhandle)) !== false) {
        if ($file != '.' && $file != '..' && !in_array($file, $exclude_directories)) {
            if (!is_dir($dir . '/' . $file) && check_view_extension($file)) {
                if ($sort_by_date) {
                    $file = filemtime($dir . '/' . $file) . $file;
                }
                array_push($myFiles, fix_encoding($file, $fix_utf8));
            }
        }
    }
    closedir($dirhandle);
    if ($sort_by_date) {
        usort($myFiles, 'mycmp_date');
    } else {
        usort($myFiles, 'mycmp');
    }
    // now we have the same order as in the listing and check if we have one or multiple indexes !
    if (strpos($index, ',') === false) {
        // only 1 selection
        return get_decoded_string($dir, $myFiles[$index]);
    } else {
        // we return an array !
        // we need the offset
        $offset = parseInputParameter($_GET['offset']);
        $filenames = array();
        $index = trim($index, ',');
        $indices = explode(',', $index);
        foreach ($indices as $ind) {
            $filenames[] = get_decoded_string($dir, $myFiles[$ind - $offset]);
        }
        return $filenames;
    }
}
コード例 #2
0
ファイル: tfu_helper.php プロジェクト: jmp0207/w3studiocms
function getFileName($dir)
{
    global $fix_utf8, $exclude_directories;
    $sort_by_date = $_SESSION["TFU_SORT_FILES_BY_DATE"];
    if (!isset($_GET['index'])) {
        return "";
    }
    $index = $_GET['index'];
    // All files are sorted in the array myFiles
    $dirhandle = opendir($dir);
    $myFiles = array();
    while (($file = readdir($dirhandle)) !== false) {
        if ($file != "." && $file != ".." && !in_array($file, $exclude_directories)) {
            if (!is_dir($dir . '/' . $file)) {
                if ($sort_by_date) {
                    $file = filemtime($dir . '/' . $file) . $file;
                }
                if ($fix_utf8 == "") {
                    array_push($myFiles, utf8_encode($file));
                } else {
                    array_push($myFiles, iconv($fix_utf8, "UTF-8", $file));
                }
            }
        }
    }
    closedir($dirhandle);
    if ($sort_by_date) {
        usort($myFiles, "mycmp_date");
    } else {
        usort($myFiles, "mycmp");
    }
    // now we have the same order as in the listing and check if we have one or multiple indexes !
    if (strpos($index, ",") === false) {
        // only 1 selection
        return get_decoded_string($dir, $myFiles[$index]);
    } else {
        // we return an array !
        // we need the offset
        $offset = $_GET['offset'];
        $filenames = array();
        $index = trim($index, ",");
        $indices = explode(",", $index);
        foreach ($indices as $ind) {
            $filenames[] = get_decoded_string($dir, $myFiles[$ind - $offset]);
        }
        return $filenames;
    }
}
コード例 #3
0
ファイル: tfu_helper.php プロジェクト: xenten/swift-kanban
function getFileName($dir)
{
    global $fix_utf8, $exclude_directories, $sort_files_by_date, $hide_hidden_files, $enable_enhanced_debug, $use_index_for_files;
    if (!$use_index_for_files) {
        // used for position critical stuff like delete, rename...
        if (isset($_POST['tfu_file_name'])) {
            $filename_post = $_POST['tfu_file_name'];
            $filename = $dir . '/' . fix_decoding($filename_post, $fix_utf8);
            if (file_exists($filename)) {
                return $filename;
            } else {
                tfu_debug("Check the encoding settings. Files canot be found when sent from the flash. If you get this error and you cannot fix this with the encoding please use the old index way and set \$use_index_for_files=false. See TFU FAQ 21.");
                return "_FILE_NOT_FOUND";
            }
        }
        // xdelete, copymove !!!  Because there can be many files!
        if (isset($_POST['tfu_file_names'])) {
            $filenames = array();
            $filenames_post_array = explode('||', $_POST['tfu_file_names']);
            foreach ($filenames_post_array as $filename_post) {
                $filename = $dir . '/' . fix_decoding($filename_post, $fix_utf8);
                if (file_exists($filename)) {
                    $filenames[] = $filename;
                } else {
                    tfu_debug("Check the encoding settings. Files canot be found when sent from the flash. If you get this error and you cannot fix this with the encoding please use the old index way and set \$use_index_for_files=false. See TFU FAQ 21.");
                    return "_FILE_NOT_FOUND";
                }
            }
            return $filenames;
        }
    }
    if (!isset($_GET['index']) || $_GET['index'] == '') {
        return '';
    }
    $index = parseInputParameter($_GET['index']);
    // All files are sorted in the array myFiles
    $dirhandle = opendir($dir);
    $myFiles = array();
    while (($file = readdir($dirhandle)) !== false) {
        if ($file != '.' && $file != '..' && !in_array($file, $exclude_directories) && !($hide_hidden_files && strpos($file, '.') === 0)) {
            if (!is_dir($dir . '/' . $file) && check_view_extension($file)) {
                if ($sort_files_by_date) {
                    $file = filemtime($dir . '/' . $file) . $file;
                }
                array_push($myFiles, fix_encoding($file, $fix_utf8));
            }
        }
    }
    closedir($dirhandle);
    if ($sort_files_by_date) {
        usort($myFiles, 'mycmp_date');
    } else {
        usort($myFiles, 'mycmp');
    }
    // now we have the same order as in the listing and check if we have one or multiple indexes !
    if (strpos($index, ',') === false) {
        // only 1 selection
        if (isset($myFiles[$index])) {
            return get_decoded_string($dir, $myFiles[$index]);
        } else {
            if ($enable_enhanced_debug) {
                tfu_debug("File index not found.");
            }
            return "_FILE_NOT_FOUND";
        }
    } else {
        // we return an array !
        // we need the offset
        $offset = parseInputParameter($_GET['offset']);
        $filenames = array();
        $index = trim($index, ',');
        $indices = explode(',', $index);
        foreach ($indices as $ind) {
            $filenames[] = get_decoded_string($dir, $myFiles[$ind - $offset]);
        }
        return $filenames;
    }
}