search and echo results as links

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Mon Apr 08, 2013 12:50 pm

search and echo results as links

Postby captaingreen » Mon Apr 08, 2013 1:00 pm

can some one help me a simple search engine which will search file name and display it(all) when they found only from specific folder

i have a folder named 'Uploads' which i have only .pdf files and i want to search them using my search form and display if the file name match as a link ready for client to download

below is the code am trying but is just displaying all the files in the folder

Code: Select all

<form action="search.php" method="post"  class="f">
   <input type="image" src="sys/searchthis.png" class="search">
    <input type="text" placeHolder="Search File" width="30" class="Height" name="search">



//get only .pdf files from uploads folder
$files_list = glob("uploads/*.pdf");

foreach($files_list as $files)
 echo $files;
 echo '<br />';


php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Re: search and echo results as links

Postby seandisanti » Mon Apr 08, 2013 3:54 pm

check out scandir() to get a file list, and then normal pattern matching by your preferred method (regex, strstr, etc) will solve your problem in no time.

Return to “PHP coding => General”

Who is online

Users browsing this forum: Bing [Bot] and 6 guests