php循环目录下的文件并把文件里面的内容循环写
作者:广州小程序开发 时间:2018-03-17 11:30
php循环目录下的文件并把文件里面的内容循环写入数据库
function read_all_dir ( $dir ) { $result = array(); $handle = opendir($dir); if ( $handle ) { while ( ( $file = readdir ( $handle ) ) !== false ) { if ( $file != '.' && $file != '..') { $cur_path = $dir . DIRECTORY_SEPARATOR . $file; if ( is_dir ( $cur_path ) ) { $result['dir'][$cur_path] = read_all_dir ( $cur_path ); } else { $result['file'][] = $cur_path; } } } closedir($handle); } return $result; } $dir = "D:/ruanjian/wamp/www/www.mytp5.com/qq"; $arr = read_all_dir($dir); foreach($arr as $k=>$v){ foreach($v as $fj){ $fp_in = fopen($fj, "r"); while (!feof($fp_in)) { $line = fgets($fp_in); $u =$line.'@qq.com'; Db::execute("insert into tp_users (email ,password) values ('$u' ,1)"); } } }