flopez1974 Posted November 19, 2013 Share Posted November 19, 2013 I am having difficulty figuring out why links to the results of my query are not working. In other words, users search for a folder name ex. 22-21-11, PDF files appear that reside in this folder as links. When a user clicks on the link, nothing happens. Everything is working great except for this portion. I am a PHP newbie and a nudge in the right direction will be greatly appreciated. I am suspecting the path I am using but I will let the PHP Jedi's comment. <?php // CMM_Tino.php error_reporting(E_ALL); /** * SEARCH FOR PDF FILES BASED ON DIRECTORY NAME */ // ACTIVATE THIS TO SHOW THE REQUEST // var_dump($_GET); // LINKS TO THE PDF FILES, IF ANY $links = NULL; // PUT THE PATH TO THE DIRECTORY OF FILE FOLDERS HERE $path = 'D:/CMM_Search/CMM'; // GET THE LIST OF FILE FOLDERS $folders = array_diff(scandir($path), array('.','..')); // FILTER THE LIST OF FILE FOLDERS TO REMOVE EXTRANEOUS FILES foreach ($folders as $key => $name) { if (!is_dir($path . DIRECTORY_SEPARATOR . $name)) unset($folders[$key]); } // IF THERE IS A REQUEST $q = !empty($_GET['q']) ? $_GET['q'] : NULL; if (!empty($q)) { // IF THE REQUEST MATCHES ONE OF THE FILE FOLDERS $folder = NULL; foreach ($folders as $folder) { if (strpos($folder, $q) !== FALSE) break; $folder = NULL; } if ($folder) { $links = "<p><b>$folder</b></p>" . PHP_EOL; // GET THE LIST OF FILES IN THE FOLDER $files = array_diff(scandir($path . DIRECTORY_SEPARATOR . $folder), array('.','..')); // PREPARE LINKS TO THE PDF FILES foreach ($files as $file) { $end = explode('.', $file); $end = end($end); $end = strtoupper($end); if ($end != 'PDF') continue; $links .= '<br>' . '<a target="my_pdf" ' . 'href="' . $path . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . $file . '">' . $file . '</a>' . PHP_EOL ; } } else { $links = '<br>' . 'Unknown Folder: ' . "<b>$q</b>" . PHP_EOL ; } } // CREATE THE SEARCH PAGE USING PHP HEREDOC NOTATION $htm = <<<EOD <!DOCTYPE html> <html> <head> <title>Barfield CMM Lookup</title> <meta name="ROBOTS" content="NOINDEX, NOFOLLOW" /> <!-- CSS styles for standard search box --> <style type="text/css"> #tfheader{ background-color:#; } #tfnewsearch{ float:left; padding:20px; width: 1686px; } .tftextinput{ margin: 0; padding: 5px 15px; font-family: Arial, Helvetica, sans-serif; font-size:14px; border:1px solid #0076a3; border-right:0px; border-top-left-radius: 5px 5px; border-bottom-left-radius: 5px 5px; } .tfbutton { margin: 0; padding: 5px 15px; font-family: Arial, Helvetica, sans-serif; font-size:14px; outline: none; cursor: pointer; text-align: center; text-decoration: none; color: #ffffff; border: solid 1px #0076a3; border-right:0px; background: #0095cd; background: -webkit-gradient(linear, left top, left bottom, from(#00adee), to(#0078a5)); background: -moz-linear-gradient(top, #00adee, #0078a5); border-top-right-radius: 5px 5px; border-bottom-right-radius: 5px 5px; } .tfbutton:hover { text-decoration: none; background: #007ead; background: -webkit-gradient(linear, left top, left bottom, from(#0095cc), to(#00678e)); background: -moz-linear-gradient(top, #0095cc, #00678e); } /* Fixes submit button height problem in Firefox */ .tfbutton::-moz-focus-inner { border: 0; } .tfclear{ clear:both; } .auto-style1 { width: 915px; height: 90px; margin-left: 0px; } .auto-style2 { color: #0033CC; } </style> </head> <body> <!-- HTML for SEARCH BAR --> <div id="tfheader"> <br /> <img alt="Barfield" class="auto-style1" src="Barfield.jpg" /><br /> <!-- ************** NOTE THE $links VARIABLE WILL BE FILLED IN BY THE PHP SCRIPT ************** --> $links <br /> <!-- ************** NOTE THE ACTION ATTRIBUTE IS REMOVED TO CAUSE THIS SCRIPT TO SEND THE FORM REQUEST TO THE CURRENT URL ************** --> <form id="tfnewsearch" method="get"> <span class="auto-style2"><strong>CMM</strong></span> <input type="text" class="tftextinput" name="q" size="21" maxlength="120"><input type="submit" value="search" class="tfbutton"> </form> <br /> <div class="tfclear"></div> </div> <!-- Use of this code assumes agreement with the Google Custom Search Terms of Service. --> <!-- The terms of service are available at http://www.google.com/cse/docs/tos.html --> <form name="cse" id="searchbox_demo" action="http://www.google.com/cse"> <input type="hidden" name="cref" value="" /> <input type="hidden" name="ie" value="utf-8" /> <input type="hidden" name="hl" value="" /> </form> <script type="text/javascript" src="https://www.google.com/cse/tools/onthefly?form=searchbox_demo&lang="></script> </body> </html> EOD; // WRITE THE HTML DOCUMENT TO THE BROWSER echo $htm; Quote Link to comment https://forums.phpfreaks.com/topic/284081-links-to-files-not-working-in-php/ Share on other sites More sharing options...
requinix Posted November 20, 2013 Share Posted November 20, 2013 (edited) Use tags when posting code. . 'You have the link pointing to a target "my_pdf" that, as far as I can see, doesn't exist anywhere on the page. Remove the target. Edited November 20, 2013 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/284081-links-to-files-not-working-in-php/#findComment-1459099 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.