User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 391,558 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,744 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 2690 | Replies: 5
Reply
Join Date: Jun 2007
Location: Albuquerque, NM
Posts: 6
Reputation: jej1216 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
jej1216's Avatar
jej1216 jej1216 is offline Offline
Newbie Poster

Can PHP search a folder for a file?

  #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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2006
Location: Sofia, Bulgaria
Posts: 135
Reputation: Rhyan is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 7
Rhyan's Avatar
Rhyan Rhyan is offline Offline
Junior Poster

Re: Can PHP search a folder for a file?

  #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  
Join Date: Aug 2005
Posts: 4,663
Reputation: iamthwee is just really nice iamthwee is just really nice iamthwee is just really nice iamthwee is just really nice 
Rep Power: 16
Solved Threads: 297
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: Can PHP search a folder for a file?

  #3  
Jun 30th, 2007
If you know what OS they use. Searching for folders/files is doable.
Member of: F-ugly code club

Join today don't delay!
Reply With Quote  
Join Date: Sep 2005
Posts: 639
Reputation: digital-ether has a spectacular aura about digital-ether has a spectacular aura about 
Rep Power: 5
Solved Threads: 38
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Practically a Master Poster

Help Re: Can PHP search a folder for a file?

  #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  
Join Date: Jun 2007
Location: Albuquerque, NM
Posts: 6
Reputation: jej1216 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
jej1216's Avatar
jej1216 jej1216 is offline Offline
Newbie Poster

Re: Can PHP search a folder for a file?

  #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  
Join Date: Apr 2005
Location: Old Hampshire, Old England (LOL)
Posts: 11,937
Reputation: jbennet is a jewel in the rough jbennet is a jewel in the rough jbennet is a jewel in the rough jbennet is a jewel in the rough 
Rep Power: 30
Solved Threads: 264
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Microsoft Fanboy

Re: Can PHP search a folder for a file?

  #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
TRY MY SUGGESTIONS AT YOUR OWN RISK!
james.bennet1@ntlworld.com
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

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

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 9:49 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC