使用PHP递归迭代类和正则表达式迭代类递归搜索目录中的.php文件。

1.1.2 2023-04-07 19:15 UTC

This package is auto-updated.

Last update: 2024-09-07 22:54:04 UTC


README

dir2db!

dir2db

  • 使用PHP递归迭代类和正则表达式迭代类递归搜索目录中的.php文件。

  • 可以搜索任何文件扩展名,也可以通过传递正则表达式搜索一组文件扩展名。请参阅帮助说明(在cmd中运行dir2db.php)

  • 某些命名的目录可以排除在搜索之外,同样可以通过在cmd中传递正则表达式来实现(请参阅dir2db.php中的帮助说明)

设置

通过git clone https://github.com/RobertByrnes/dir2db.git安装,然后进入包根目录并运行composer deploy-ini

使用dir2db.sql将file_contents表安装到MySQL数据库中。

例如,运行mysql -u {$databaseUser} -p {$databaseName} < dir2db.sql

编辑./private/local.ini,以包含正确的数据库凭据。

使用

在CMD/终端中键入'php dir2db.php',这将显示帮助菜单

    /*** ARGUMENTS ***/
    Required arguments:
        -p path, e.g. c:/wamp/www/
    Optional arguments: 
        -r regex, to filter file search to only include certain file extension. Default: /\.(?:php)$/
        -e exclusions, directories ommited during search e.g. vendor|node_modules|private *Must include pipe*
        -h help, prints this help message.";

示例

  1. php dir2db.php -p c:/wamp/www/repositories
  2. php dir2db.php -p c:/wamp/www/repositories -r "/\.(?:txt)$/"
  3. php dir2db.php -p c:/wamp/www/repositories -r "/\.(?:txt)$/" -e vendor|node_modules
  4. php dir2db.php -p c:/wamp/www/repositories -r "/\.(?:txt|ini|sql)$/" -e vendor|node_modules
  • 示例1将在repositories目录中搜索所有目录下的php文件
  • 示例2将在repositories中搜索.txt文件
  • 示例3与示例2相同,但还排除了名为'vendor'或'node_modules'的目录中的内容
  • 示例4演示了如何使用正则表达式包含多个文件扩展名

内存限制!

如果您看到致命异常 - 允许的内存限制,请重新运行您的命令,如下所示

  • php .\dir2db.php -p c:/dir2db -r "/\.(?:jpg|png|pdf|php)$/" -e "vendor|node_modules"
  • php -d memory_limit=-1 .\dir2db.php -p c:/dir2db -r "/\.(?:jpg|png|pdf|php)$/" -e "vendor|node_modules"

-d memory_limit=-1将告诉PHP在执行此过程时忽略内存限制。

关于二进制文件类型的说明

  • 以下二进制文件类型受支持
  • 'pdf', 'jpg', 'jpeg', 'png', 'gif', 'svg', 'ico', 'bmp', 'tiff', 'tif', 'webp'
  • 这些文件的文件内容将存储在binary_file_content数据库列中,该列的类型为LONGBLOB
  • 不在该列表中的文件将存储在file_content列中,该列的类型为LONGTEXT

FileFinder特性

The FileFinder trait uses PHP's recursive iterator classes to search for files in a directory structure returning an array of results.

用法

要使用FileFinder特性,请使用以下参数调用fileFinder方法

  • $path - 要搜索的目录路径
  • $fileFilter(可选)- 用于查找PHP文件扩展的正则表达式
  • $directoryFilter(可选)- 要排除的目录名称

fileFinder方法将返回结果数组。

Files!