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
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
	}
}
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.