Jump to content

PHP file search engine script


tschroeder

Recommended Posts

Hello,
 

I'm a beginner in php developing and I want to bring advanced file search functionality in my php web application.
 

How could I realize that?
 

I want to build a search form within my php web site which gives the users the possibility to search for files  which are saved in a special directory on my webserver. This directory contains only files which are uploaded by registrated users.
 

The script I need should check files' names but also the files' contents.
 

Any ideas? I think there must be existing scripts - freeware or commercial stuff.
 

Could anybody help me?
 

Thanks
 

Thomas

 

Link to comment
https://forums.phpfreaks.com/topic/278318-php-file-search-engine-script/
Share on other sites

I don't think there would be such a script that checks the file's contents, as different file types have different ways to be read. A simple code snippet I can give you:

<?php

$dir = "./repository/"; // The folder where all the files are
$search = "text"; // This can also be a POST or a GET, or whatever. It will search for anything with the file name containing "text" (text.jpg, subtext.exe, etc.)

// Code
foreach(glob($dir."*") as $key => $value) {
	$file = str_replace($dir, "", $value);
	if(is_int(strpos($file, $search))) {
		echo $file . "<br />";	// Echo the file that matches what you were looking for
	}
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.