Чтобы вывести выходные изображения в каталог с помощью PHP, вы можете использовать несколько методов. Вот несколько примеров с соответствующим кодом:
Метод 1. Использование функций opendir(), readdir() и closedir()
$directory = '/path/to/directory';
// Open the directory
$dirHandle = opendir($directory);
// Loop through the directory and read each file
while (($file = readdir($dirHandle)) !== false) {
// Check if the file is an image (you can modify this condition based on your requirements)
if (is_file($directory . '/' . $file) && getimagesize($directory . '/' . $file)) {
echo $file . '<br>';
}
}
// Close the directory handle
closedir($dirHandle);
Метод 2: использование функции glob()
$directory = '/path/to/directory';
// Get all image files in the directory
$imageFiles = glob($directory . '/*.jpg');
// Loop through the image files
foreach ($imageFiles as $file) {
echo basename($file) . '<br>';
}
Метод 3: использование класса DirectoryIterator
$directory = '/path/to/directory';
// Create a new DirectoryIterator object
$dirIterator = new DirectoryIterator($directory);
// Loop through the directory
foreach ($dirIterator as $file) {
// Check if the file is a regular file and is an image (you can modify this condition based on your requirements)
if ($file->isFile() && getimagesize($file->getPathname())) {
echo $file->getFilename() . '<br>';
}
}