Current location: Hot Scripts Forums » General Community » Script Requests » Filename Search Script


Filename Search Script

Reply
  #1 (permalink)  
Old 12-13-04, 10:14 PM
epheterson epheterson is offline
Newbie Coder
 
Join Date: Nov 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Filename Search Script

I have an upload directory on my site, it has become far too large to load the entire directory listing to download one file, my idea for a solution is a simple search script. Most of the time, when going there, I know all or part of the filename I need, so a script that searches a directory for filenames and returns a list of links would be a perfect solution.

Nice and simple: How can I make a script that searches a directory for filenames and returns a list of all matches?
Reply With Quote
  #2 (permalink)  
Old 12-14-04, 12:11 AM
HockeyGod HockeyGod is offline
Newbie Coder
 
Join Date: Dec 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
I just coded you what you'd like.

I listed it on hotscripts as Listfiles.php but obviously it's not up yet

Here is a link to my site where you will find the script to download, and an example of it in action:

http://design.thehockeygod.com/?pid=scripts


You're welcome.
Reply With Quote
  #3 (permalink)  
Old 12-14-04, 12:22 AM
epheterson epheterson is offline
Newbie Coder
 
Join Date: Nov 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
It's almost exactly what I'm looking for!

Few changes to fit my needs though, I can't have it show an entire directory listing, as this is a way to get around having to do that. The search has to be more strict, only showing a file if what is in the search box is in the filename (no exceptions). Lastly, I'd like the link to open the program in the same window.

Also, a minor bug is when changing the search directory, all links fail to work (they link to the root directory). And, although a nice feature, the thumbnail option is impractical. Instead of creating a thumbail cache, it displays the actual image resized. A lot of the pictures uploaded to a random upload directory can be close to or over a meg, and downloading over a thousand of them for one page can really take some time. If it cropped and resized them, then created a cache, it'd be an amazing way to find images faster!

Thank you SO much for what you've done so far!

Last edited by epheterson; 12-14-04 at 12:30 AM.
Reply With Quote
  #4 (permalink)  
Old 12-14-04, 12:15 PM
HockeyGod HockeyGod is offline
Newbie Coder
 
Join Date: Dec 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Easy Fixes.

1.) Delete the last ELSE block. The code does this "if q isset, show seach results, else if images is set, show only images, else show all files. Just chop off the else show all files, and if no options are set it will just show the options at the top.

2.) Look for the echo statements, remove the target='_blank' parts in there. It should appear once in each case, so 3 times all together (2 if you remove the last else block)

For images, I didn't want to mess with creating new stuff on the server and taking up more space, so I just used what's there. Again, copying the code from the file part and pasting it into the image part will make it just show hyperlinks to images

As for doing the thumbnail cache, I wish I had time to do that, but I don't.

I'm glad you find it useful though

--HG
www.thehockeygod.com
Reply With Quote
  #5 (permalink)  
Old 12-14-04, 01:19 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Post Paging?

Quote:
Originally Posted by epheterson
I have an upload directory on my site, it has become far too large to load the entire directory listing to download one file,
Ummm, why don't you page the output? Here's some generic paging code that's meant for use with mySQL, but could easily be modified to work with the directory listing that HockeyGod wrote.

---------------------------------------------
// set rows per page
$rows_per_page = 5;

if (isset($_GET['pageno'])) {
$pageno = $_GET['pageno'];
} else {
$pageno = 1;
}

// Identify how many database rows are available
// This code will count how many rows will satisfy the current query.
$query = "SELECT * FROM users WHERE user_id = $something";

$result = mysql_query($query);

$query_data = mysql_fetch_row($result);

$numrows = $query_data[0];

// Calculate number of $lastpage
// This code uses the values in $rows_per_page and
// $numrows in order to identify the number of the last page.

$lastpage = ceil($numrows/$rows_per_page);


// This code checks that the value of $pageno is an integer between 1 and $lastpage.
$pageno = (int)$pageno;
if ($pageno < 1) {
$pageno = 1;
} elseif ($pageno > $lastpage) {
$pageno = $lastpage;
}


// Construct LIMIT clause
//This code will construct the LIMIT clause for the sql SELECT statement.

$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;


// Issue the database query
// Now we can issue the database qery and process the result.

// get the users who exist and have entries in the 'trv_ustat' table
$query = "SELECT * FROM trv_users, trv_ustat WHERE trv_users.user_id = trv_ustat.id ORDER BY user_id $limit";

$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);


//... process contents of $result ...

(....do something here with your code....)



// Construct pagination hyperlinks
// Construct the hyperlinks which will allow the user to select
// other pages.

if ($pageno == 1) {
$first_prev = " FIRST &nbsp; << PREV ";
} else {
$first_prev = " [<a href='{$_SERVER['PHP_SELF']}?pageno=1' class='nav'>FIRST</a>]&nbsp;";
$prevpage = $pageno-1;
$first_prev = $first_prev . "&nbsp;<a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage' class='nav'><< PREV</a> ";
}


// Next, show the user his current position in the sequence of available pages.
echo " ( Page $pageno of $lastpage ) ";


// This code will provide the links for any following pages.
if ($pageno == $lastpage) {
$next_last = " NEXT >> &nbsp; LAST ";
} else {
$nextpage = $pageno+1;
$next_last = " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage' class='nav'>$NEXT >></a>&nbsp;";
$next_last = $next_last . "&nbsp;[<a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage' class='nav'>LAST</a>] ";
}


print <<<EOM
<center>[ Page $pageno of $lastpage ]</center>
<table width='100%' cellpadding="1" cellspacing="1" border="0>
<tr align="center" bgcolor="$headcol"><td width="25%" valign="middle">&nbsp;</td>
<td align="center" valign="middle">

$first_prev $sep_char1 $next_last

</td>
<td width="25%" align="right">
<a href="$good_login" class="nav">$back_to_homepage</a></td>
</tr></table>
</center><br>
EOM;
Reply With Quote
  #6 (permalink)  
Old 12-14-04, 04:49 PM
epheterson epheterson is offline
Newbie Coder
 
Join Date: Nov 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
HockeyGod, that's getting closer to exactly what I want. I need the search parameters to be more accurate, though, returning results only if what is typed (entirely) can be found in the filename. For example, if i type 'dog', files are returned named dog.gif, hotdog.jpg, dogzarecool.exe, etc... but not files like hog, jog, dot, etc..

How could I go about making changes for that to work properly? I upped the required similarity to 50 and got more acurate results, but still not quite what I need.
Reply With Quote
  #7 (permalink)  
Old 12-15-04, 03:54 AM
HockeyGod HockeyGod is offline
Newbie Coder
 
Join Date: Dec 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
In the call to is_similar() (the function I wrote), the 3rd parameter is a percent.

I think I used 15.

IE if at least 15% of the characters in teh 2 strings are the same, it returns it as a result.


If you want it lower, just change that percentage.
Reply With Quote
  #8 (permalink)  
Old 12-15-04, 07:17 AM
epheterson epheterson is offline
Newbie Coder
 
Join Date: Nov 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
I did change the percentage, but what I'm saying is that's not how I need it to search. I need it to see if that is in the filename, not search by similarity.
Reply With Quote
  #9 (permalink)  
Old 12-17-04, 02:37 PM
HockeyGod HockeyGod is offline
Newbie Coder
 
Join Date: Dec 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
use this:

if (preg_match("/$searchstring/i", "$files[$i]"))
// then it's a match

instead of checking similarity.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hep with Simple Search script pentatonic145 General HotScripts Site Discussion 0 06-30-04 02:31 PM
mysql/php search script dawggy505 PHP 1 06-22-04 06:49 AM
Simple search script niceguyonline Script Requests 3 03-07-04 11:09 PM
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM


All times are GMT -5. The time now is 10:56 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.