file_index_refresh.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. include "../path.php";
  3. include "./_pdo.php";
  4. //获取服务器端文件列表
  5. $dir = _DIR_USER_DOC_ . '/' . $_COOKIE["userid"] . '/' . _DIR_MYDOCUMENT_ . "/";
  6. PDO_Connect( _FILE_DB_FILEINDEX_);
  7. $files = scandir($dir);
  8. $arrlength = count($files);
  9. // 开始一个事务,关闭自动提交
  10. $PDO->beginTransaction();
  11. $query = "INSERT INTO fileindex ('id','file_name','title','create_time','modify_time','accese_time','file_size') VALUES (NULL,?,?,?,?,?,?)";
  12. $stmt = $PDO->prepare($query);
  13. for ($x = 0; $x < $arrlength; $x++) {
  14. if (is_file($dir . $files[$x])) {
  15. $ctime = filectime($dir . $files[$x]);
  16. $mtime = filemtime($dir . $files[$x]);
  17. $atime = fileatime($dir . $files[$x]);
  18. $filesize = filesize($dir . $files[$x]);
  19. $newData = array($files[$x], "title", $ctime, $mtime, $atime, $filesize);
  20. $stmt->execute($newData);
  21. //echo $files[$x].',';
  22. }
  23. }
  24. // 提交更改
  25. $PDO->commit();
  26. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  27. $error = PDO_ErrorInfo();
  28. echo "error - $error[2] <br>";
  29. } else {
  30. echo "updata $arrlength recorders.";
  31. }