我想創建一個在文件(文件類型:.doc,.docx,.pdf)中搜索的模塊。通過使用「file_get_contents()」我可以找到文件,但爲此我必須指定所有文件的位置。在我的情況下,我有許多文件夾中的文件(如:C:\ xampp \ htdocs \ cats1 \ attachments \ site_1 \ 0xxx ..)文件始終存儲在「0xxx」文件夾中(由其他應用程序)。我只想指定路徑,以便無論「0xxx」文件夾包含多少個「文件夾」,它都會在其中進行搜索。我對PHP很陌生,請幫忙。我的這個應用程序的代碼如下。在mysql數據庫的文本文件(.doc,.docx,.pdf等)中搜索
<?php
$matched_files = array();
if(isset($_POST['submit']))
{
$skills = $_POST['skills'];
$experience= $_POST['experience'];
$location = $_POST['location'];
$path = 'C:\Docs';
$dir = dir($path);
// Get next file/dir name in directory
while (false !== ($file = $dir->read()))
{
if ($file != '.' && $file != '..')
{
// Is this entry a file or directory?
if (is_file($path . '/' . $file))
{
// Its a file, yay! Lets get the file's contents
$data = file_get_contents($path . '/' . $file);
// Is the str in the data (case-insensitive search)
if (stripos($data, $skills) !== false and (stripos($data, $experience) !== false and (stripos($data, $location) !== false)))
{
$matched_files[] = $file;
}
}
}
}
$dir->close();
$matched_files_unique = array_unique($matched_files);
}
?>
不是文本文件,你就必須提取文本搜索他們 – 2014-01-27 23:13:08
您的數據庫實際存儲的文件的文本,或者它存儲的文件的名稱和位置? – miyasudokoro