0
 <html>
    <body>
    <table>
    <form action="" method="GET">
    <tr><td>Please Enter your KCSE Index Number</td><td><input type="text" id="index_no" name="q" value=""></td></tr>
   <tr><td></td><td><input type="Submit" id="print"  value="Search"></td></tr>
    </form>
    </table>    
    </body>
    </html>

<?php
$dir = 'C:\wamp\www\test\admisssionletters'; 
$exclude = array('.','..','.htaccess'); 
$q = (isset($_GET['q']))? strtolower($_GET['q']) : ''; 
$textarea=$_GET['q'];
$res = opendir($dir); 
while(false!== ($file = readdir($res))) 
{ 
if(strpos(strtolower($file),$q)!== false &&!in_array($file,$exclude)) 

    { 
    echo "Click to download or Print your Adm Letter      <ahref='$dir/$file'>$file</a>"; 
    echo "<br>"; 
    } 
} 
closedir($res); 
?>

1. the download link isnt working

c:\wamp\www\test\admisssionletters/20400003066_2014.pdf

however if the slash preceding the file name is changed to:

  c:\wamp\www\test\admisssionletters\20400003066_2014.pdf

it works, how can i change this in the code?

2. i would also like to restrict values entered in the input text to a specific number, how do i achieve this?

Passionate Coder
  • 7,154
  • 2
  • 19
  • 44

1 Answers1

0

You can't use the location on disk as a hyperlink. That location only makes sense if you're actually on the computer where the file is stored. If you're on another computer, viewing the website (remotely, don't forget) then

'C:\wamp\www\test\admisssionletters\20400003066_2014.pdf';

means the C drive of the computer being used to view the site, not the computer where the site is hosted. Or, if you're not using a Windows PC, it means nothing at all!

Hyperlinks are of the form http://hostname/resource and point to your webserver, which then decides what to do with them. It might point to a real file on disk or it might not (if you use a framework or something to interpret the URLs). In your case I would guess that C:\wamp\www is probably the root folder that your webserver is hosting files from. Let's also assume, just for example, that your computer's hostname is "mycomputer". Therefore the link to C:\wamp\www\test\admisssionletters\20400003066_2014.pdf that you need to display on the website would be

http://mycomputer/test/admisssionletters/20400003066_2014.pdf
ADyson
  • 57,178
  • 14
  • 51
  • 63
  • thanks alot @siddesh i managed to get it work. however in my folder i have several files: 20400003066_2014.pdf, 34400003066_2014.pdf, 20400045326_2014.pdf as u can see these 3 files share some digits. if i type for example 000 the three files will display but i want i specific one. please assist me to restrict the entered number of characters and not to display several files at once. – Ochwachi Jul 15 '16 at 05:51
  • @Ochwachi what is the minimum and maximum number of characters that you want to restrict it to? – ADyson Jul 15 '16 at 09:12
  • minimum 7 maximum 11 – Ochwachi Jul 22 '16 at 09:52
  • @Ochwachi change your textbox like this: `` For more info see http://www.w3schools.com/tags/att_input_pattern.asp and http://stackoverflow.com/questions/10281962/is-there-a-minlength-validation-attribute-in-html5 – ADyson Jul 22 '16 at 10:12
  • Very Helpfull @ADYson – Ochwachi Jul 28 '16 at 13:00
  • ok no problem, please accept the answer if it (plus the comments) has helped you. – ADyson Jul 28 '16 at 13:01