时间:2021-07-01 10:21:17 帮助过:33人阅读
$user = 'root';
$pass = 'thrope';
$dbh = new PDO('mysql:host=localhost;dbname=income', $user, $pass);
$query = 'insert into picinfo set picpath=:pp, picsize=:ps';//把文件路径和文件大小写入数据库
$stmt = $dbh->prepare($query);
function dir_read($dir){
$dh = opendir($dir);//if (is_dir($dir)) echo realpath($dir).'
';
while (false !== ($filename = readdir($dh))){//echo realpath($dir.'/'.$filename).'
';
//if ($filename == '.' || $filename == '..') continue;
if (is_file($dir.'/'.$filename)){
global $stmt;
$stmt->execute(array(':pp'=>realpath($dir.'/'.$filename), ':ps'=>filesize(realpath($dir.'/'.$filename))));
//echo $dbh->errorCode();
}
if (is_dir(realpath($dir.'/'.$filename)))//这个递归调用特别耗费资源
dir_read(realpath($dir.'/'.$filename));
}
closedir($dh);
}
dir_read('K:/project/fileOperate');