function autoload($path, $class)
{
    // Conteúdo da função "__autoload"
    $folder = $path . "class";
    $class .= ".php";
    $file = searchFiles($folder, $class);
    if ($file !== false) {
        require_once $file;
    } else {
        AJAXReturn("{'type':'error','message':'Não foi possível encontrar o arquivo \\'{$class}\\'.'}");
    }
}
function searchFiles($list, $needle)
{
    $result = array();
    foreach ($list as $key => $value) {
        if (strpos($value, $needle)) {
            $result[] = $value;
        }
    }
    return $result;
}
if (isset($_GET['link'])) {
    $link = $_GET['link'];
} elseif (isset($_GET['zoeken'])) {
    $getZoek = $_GET['zoeken'];
    $link = 'zoeken';
    $zoekresultaat = searchFiles($list, $getZoek);
} else {
    $link = '';
    $getZoek = '';
}
?>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Herhalingsoefening</title>
	<link rel="stylesheet" type="text/css" href="http://web-backend.local/css/global.css">
	<link rel="stylesheet" type="text/css" href="http://web-backend.local/css/directory.css">
	<link rel="stylesheet" type="text/css" href="http://web-backend.local/css/facade.css">
<?php

function searchFiles($path, $word, $withFolders = 1)
{
    $dataArr = scandir($path);
    $dataArr = array_diff($dataArr, ['.', '..']);
    foreach ($dataArr as $data) {
        if (!$withFolders and is_dir($data)) {
            continue;
        }
        $pattern = '/' . $word . '/';
        if (preg_match($pattern, $data)) {
            $files[] = $data;
        }
    }
    return sizeof($files) ? $files : false;
}
$allData = searchFiles('.', '0', 1);
foreach ($allData as $data) {
    echo $data . '<br>';
}
Example #4
0
File: util.php Project: sziszu/pefi
function copyFiles($source, $suffixes, $dest_dir)
{
    if (!is_dir($dest_dir)) {
        mkdir($dest_dir);
    }
    $files = array();
    $files = array_merge($files, searchFiles($source, $suffixes));
    foreach ($files as $file) {
        if (is_dir("{$source}/{$file}")) {
            copyFiles("{$source}/{$file}", $suffixes, "{$dest_dir}/{$file}");
        } else {
            copy("{$source}/{$file}", "{$dest_dir}/{$file}");
        }
    }
}