Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ask PHP to find filename that contains something

Tags:

php

im trying to do this :

$filename = "/destination/destination2/file_*";

" * " = anything

destination2 files :

file_somethingrandom

and since it $filename contains * so it should be selecting file_somethingrandom

how to do it?

like image 924
Lili Abedinpour Avatar asked Dec 07 '22 15:12

Lili Abedinpour


2 Answers

Use the glob() function like this:

$filename = "/destination/destination2/file_*";
foreach (glob($filename) as $filefound)
{
    echo "$filefound size " . filesize($filefound) . "\n";
}
like image 178
roychri Avatar answered Dec 09 '22 03:12

roychri


Try this

foreach (glob("/destination/destination2/file_*") as $filename) {
    echo $filename;
}

Cheers!

like image 32
A.N.M. Saiful Islam Avatar answered Dec 09 '22 04:12

A.N.M. Saiful Islam