Esempio n. 1
0
/**
 * Find the files present in a folder, and sub-folder.
 * 
 * @param string $path The path to look into.
 * @param boolean $recurse Trigger the recursion, default to True.
 * @param boolean $include_hidden Trigger the listing of hidden files / hidden directories, default to False.
 * @access public
 * @return array A list of files present in the inspected folder (paths are relative to the inspected folder path).
 */
function getFolderContents($path, $recurse = true, $include_hidden = false)
{
    if (!is_dir($path)) {
        return array();
    }
    // Test if the path is not a folder.
    $directory_handle = opendir($path);
    if ($directory_handle === false) {
        return array();
    }
    // Test if the directory listing failed.
    $files = array();
    while (($file = readdir($directory_handle)) !== false) {
        if (!in_array($file, array('.', '..'))) {
            if ($include_hidden || !preg_match('/^\\./', $file)) {
                $complete_path = $path . DIRECTORY_SEPARATOR . $file;
                if (is_dir($complete_path) && $recurse) {
                    $sub_dir_files = getFolderContents($complete_path, $recurse, $include_hidden);
                    foreach ($sub_dir_files as $sub_dir_file) {
                        $files[] = $file . DIRECTORY_SEPARATOR . $sub_dir_file;
                    }
                    // For each subdirectory contents.
                } elseif (is_file($complete_path)) {
                    $files[] = $file;
                }
            }
            // Test if the file can be listed.
        }
        // Test if file is not unix parent and current path.
    }
    // For each directory listing entry.
    // We close the directory handle:
    closedir($directory_handle);
    // We sort the files alphabetically.
    natsort($files);
    return $files;
}
    $titleh2 = str_replace(array("%number", "%subtitle"), array("2", $lang["upload_file"]), $lang["header-upload-subtitle"]);
    # We compute the folder name from the upload folder option.
    $folder = getAbsolutePath($local_ftp_upload_folder, true);
    if ($groupuploadfolders) {
        $folder .= DIRECTORY_SEPARATOR . $usergroup;
    }
    if ($useruploadfolders) {
        $udata = get_user($userref);
        $folderadd = htmlspecialchars($udata["username"]);
        $folder .= DIRECTORY_SEPARATOR . $folderadd;
    }
    if (!file_exists($folder)) {
        mkdir($folder, 0777);
    }
    // We list folder contents
    $files = getFolderContents($folder);
} else {
    # Connect to FTP server for file listing
    # Define the titles:
    $titleh1 = $lang["addresourcebatchftp"];
    $titleh2 = str_replace(array("%number", "%subtitle"), array("3", $lang["upload_file"]), $lang["header-upload-subtitle"]);
    $ftp = @ftp_connect(getval("ftp_server", ""));
    if ($ftp === false) {
        exit("FTP connection failed.");
    }
    ftp_login($ftp, getval("ftp_username", ""), getval("ftp_password", ""));
    ftp_pasv($ftp, true);
    $folder = getval("ftp_folder", "");
    if (substr($folder, strlen($folder) - 1, 1) != "/") {
        $folder .= "/";
    }