Home  >  Article  >  Backend Development  >  PHP traverses the files in the folder and obtains the value of the input name, _PHP tutorial

PHP traverses the files in the folder and obtains the value of the input name, _PHP tutorial

WBOY
WBOYOriginal
2016-07-12 09:03:171064browse

PHP traverses the files in the folder and obtains the value of the input name,

$dir = dirname(__FILE__); //To be traversed Directory name->The folder where the current file is located
//$dir='D:PHPwampwwwadminhostsadmin';
//PHP traverses all files in the folder
$handle=opendir($dir.". ");
$arr = array();
while($file=readdir($handle)){
 if(is_file($file)){
 if ($file != " ."&& $file != "..") {
  $file = mb_substr($file,0,strripos($file,'.'));
$files = explode(' ',$file ); //Convert $file into an array
  $arr[]=$files['0'];//Convert into a one-dimensional array
  }
 }
}
//print_r ($arr);
closedir($handle);
//PHP gets the value of input->name
foreach ($_POST AS $key=>$value){
 if( !in_array($key,$arr)){ //Check whether the name value is in $arr
  echo "$key: does not exist";
}

}
?>







 

 
 


 


 





  

 


 


 




www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1083562.htmlTechArticlePHP traverses the files in the folder and obtains the value of the input name, ?php $dir = dirname(__FILE__) ;//The name of the directory to be traversed - the folder where the current file is located //$dir='D:PHPwampwwwadmin...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn