ZaZaKi, a web developer Between Manchester UK & Rotterdam NL. © 2015-2024.

php search for file by name without file extension

 

$dir = ' folder name ';
$search_for = " file name ";

// array_diff Compare the values of two arrays, and return the differences
// scandir List files and directories inside directory
$filesInDIR = array_diff(scandir($dir), array('.', '..')); 

// remove extenstions from files
$files = preg_replace('/\\.[^.\\s]{3,4}$/', '', $filesInDIR); 

	// if file name found else ...
	if (in_array($search_for, $files)){
		echo "found";
	}else{
		echo "not found";
	}
 
 
Categroy:
back-end , PHP