Example 1 — Find a File on a Temporary Include Path
Create a temp file, put its directory on the include_path, then resolve the basename.
<?php
$dir = sys_get_temp_dir();
$file = "ctf_resolve_demo.php";
$path = $dir . DIRECTORY_SEPARATOR . $file;
file_put_contents($path, "<?php\n");
$old = get_include_path();
set_include_path($dir . PATH_SEPARATOR . $old);
$resolved = stream_resolve_include_path($file);
echo $resolved !== false ? "found" : "missing", PHP_EOL;
echo basename((string) $resolved), PHP_EOL;
set_include_path($old);
unlink($path); How It Works
- A small PHP file is written into the system temp directory.
- set_include_path() puts that directory first on the include_path.
- stream_resolve_include_path() finds the file and returns its full path.
- We print found plus the basename so the demo stays offline-safe and path-stable.

