Can PHP search a folder for a file?

Reply

Join Date: Jun 2007
Posts: 6
Reputation: jej1216 is an unknown quantity at this point 
Solved Threads: 0
jej1216's Avatar
jej1216 jej1216 is offline Offline
Newbie Poster

Can PHP search a folder for a file?

 
0
  #1
Jun 29th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 232
Reputation: Rhyan is an unknown quantity at this point 
Solved Threads: 24
Rhyan's Avatar
Rhyan Rhyan is offline Offline
Posting Whiz in Training

Re: Can PHP search a folder for a file?

 
0
  #2
Jun 29th, 2007
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.
" Of all the things I've lost,
I miss my mind the most...."
Mark Twain
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Can PHP search a folder for a file?

 
0
  #3
Jun 30th, 2007
If you know what OS they use. Searching for folders/files is doable.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,082
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: Can PHP search a folder for a file?

 
1
  #4
Jun 30th, 2007
Originally Posted by jej1216 View Post
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.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 6
Reputation: jej1216 is an unknown quantity at this point 
Solved Threads: 0
jej1216's Avatar
jej1216 jej1216 is offline Offline
Newbie Poster

Re: Can PHP search a folder for a file?

 
0
  #5
Jul 1st, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16,267
Reputation: jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all 
Solved Threads: 544
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: Can PHP search a folder for a file?

 
0
  #6
Jul 1st, 2007
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
If i am helpful, please give me reputation points.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC