How to list the files in a folder
Short answer
scandir() returns the names; remove the service entries . and ..:
<?php
$dir = sys_get_temp_dir() . '/recipe-list';
if (!is_dir($dir)) {
mkdir($dir);
}
file_put_contents($dir . '/a.txt', '');
file_put_contents($dir . '/b.jpg', '');
echo implode(', ', array_diff(scandir($dir), ['.', '..']));Output:
a.txt, b.jpgOnly the needed type
glob() searches by a mask and returns full paths:
<?php
$dir = sys_get_temp_dir() . '/recipe-list';
if (!is_dir($dir)) {
mkdir($dir);
}
file_put_contents($dir . '/a.txt', '');
file_put_contents($dir . '/b.jpg', '');
echo implode(', ', array_map('basename', glob($dir . '/*.jpg')));Output:
b.jpg