I am trying to create a php file that finds a random file in the same directory as the .php file, grab the name of that file and return it. i.e, it would return something like "text45.txt" as the output. (not the text inside the file just the file name and extension)
Ihave already tried the code below, but I cannot figure out how to make it return just the file name instead of the entire path, for example this is one of my outputs "/home/ariliswi/public_html/api/google/getrandompurchase/test.txt"
<?php
$files = glob(realpath('./') . '/*.*');
$file = array_rand($files);
echo $files[$file];
?>
I would like it to output the file name only i.e "test.txt" instead of the entire file path.
Aucun commentaire:
Enregistrer un commentaire