Going through 10,000 files will certainly take a lot of time.
Another approach would be to store the name of the last uploaded file in a file. You can then open the file get its contents (the newest file's name).
Another way would be to store the name in a database.
// upload here;
$name = 'name of the uploaded file';
// storing the name of the last uploaded file
$fp = fopen('lastuploaded', 'w');
// get the name
$fp = fopen('lastuploaded', 'r');
$data = fread($fp, filesize('lastuploaded'));
echo 'last uploaded file was: ', $data;