tschroeder Posted May 23, 2013 Share Posted May 23, 2013 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 Quote Link to comment Share on other sites More sharing options...
xenLiam Posted May 24, 2013 Share Posted May 24, 2013 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 } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.