954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Can PHP search a folder for a file?

I have a website that lists pdf files for downloading, with links to each file.

What I want to do now is design a search page that will look in the folder that contains these docs and search for docs that match a partial name.

I have created search pages for MySQL before - do I have to create a table with file names and links and then do a search of MySQL?

TIA,

jej1216

jej1216
Newbie Poster
6 posts since Jun 2007
Reputation Points: 10
Solved Threads: 0
 

It is possible, however it is said that such functions are subject to vulnerability.

Still - I have made such thing and it is quite self-maintaining page you will get out of it.
See the PHP manual for functions readdir and scandir. It is quite simple to do it.

Rhyan
Posting Whiz in Training
240 posts since Oct 2006
Reputation Points: 21
Solved Threads: 26
 

If you know what OS they use. Searching for folders/files is doable.

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

I have a website that lists pdf files for downloading, with links to each file.

What I want to do now is design a search page that will look in the folder that contains these docs and search for docs that match a partial name.

I have created search pages for MySQL before - do I have to create a table with file names and links and then do a search of MySQL?

TIA,

jej1216

It is possible to search the directories for files using the PHP file functions like mentioned. See: http://www.php.net/manual/en/function.opendir.php

You'd get better performance by indexing the files in a db like you said, since searching database rows is much faster than scanning a directory, especially if you have many files.

digital-ether
Nearly a Posting Virtuoso
Moderator
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
 

Thanks for all of the quick replies!

I'll try the opendir and scandir and see if that is quick enough for our purposes. If it's too slow, I'll do the database approach.

Rhyan - you said "It is possible, however it is said that such functions are subject to vulnerability." What vulnerablility? Hacking?

Thanks everyone.

jej1216

jej1216
Newbie Poster
6 posts since Jun 2007
Reputation Points: 10
Solved Threads: 0
 

they can be exploited to form a DoS attack
servers which have PHP safe mode enabled (most hosted ones) dont allow these potentially dangerous commands

jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,826
Solved Threads: 601
 

hi friends,
i have query...
how can i find specific file from different directory, in my PC, by PHP code ??
Is there any in-biult command??

VisHEarT
Newbie Poster
2 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
 

Thanx,

VisHEarT
Newbie Poster
2 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You