troubleshooting Question

Link referencing wrong location

Avatar of peter-cooper
peter-cooper asked on
PHP
21 Comments1 Solution131 ViewsLast Modified:
I am using the opendir to read certain files into a loop and print them in a table. This works well apart from the fact that when it comes to downloading them, they are referencing the wrong location. Instead of referencing them from the folder i set in the $dir var, they are pointing to the parent folder where my page is loaded. For example, my structure is:

users
-->destcerts

Why is it not referencing the location set in the $dir var. Thanks

<?php
   //$directory = chdir('destcerts');
   $dir = opendir('destcerts');
   echo getcwd() . "\n"; [b] --> POINTS TO USERS FOLDER WHERE MY PHP FILE IS CALLED FROM[/b]
   
   $table = '<table border="1" width="90%" cellspacing="3" cellpadding="5" align="center">
   <tr>
   <th colspan="3">Results</th>
   </tr>
   <th>File</th>
   <th>File</th>
   <th>File</th>';
   
   //List files in pdf dir
   while (($file = readdir($dir)) !== false)
   {		
   if(substr( $file, -3 ) == "pdf" )
   
   {
   //echo '<br />' . "<a href=\"" . $file . "\">" . $file . "</a>";
   
   $table .= '<tr>
   <td align="center"><img src="destcerts/PDF_icon_100.png"><br /><a href="'.$file.'" style="font-size:12px; color:blue; text-decoration:none;">'.$file.'</a></td>
   <td align="center"><img src="destcerts/PDF_icon_100.png"><br /><a href="'.$file.'" style="font-size:12px; color:blue; text-decoration:none;">'.$file.'</a></td>
   <td align="center"><img src="destcerts/PDF_icon_100.png"><br /><a href="'.$file.'" style="font-size:12px; color:blue; text-decoration:none;">'.$file.'</a></td>
   </tr>';
   
   }
   }
   
   $table .= '</table>';
   echo $table;
   
   closedir($dir);
   
   
   ?>
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 21 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 21 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros