Get the names of all files from a folder, using PHP?

Get the names of all files from a folder, using PHP?

You can do that by using the scandir php function:

A simple code:

1
2
$dir = 'images';
$extract = scandir($dir);

To show the results, use:

print_r($extract);

How to turn print_r($extract); into a variable?

Like this:

2
3
4
foreach($extract as $file)
{
}

and echo”.$file.”;

$file will be the variable.

After this, you can copy paste your results into an excel file and save the file as .csv.
You can import the .csv file into phpmyadmin.

Test file

If you have any questions, leave in the comments.

Add a comment: