通过<a> element

时间:2017-06-07 04:47:43

标签: php filepath mamp-pro

I am using MAMP Pro to manage building a website on a local machine i.e. not on the actual web. I am currently having issues showing files via providing a link to the correct URL's of the files. I was wondering how I can simulate how a real web server would behave when linking to files already uploaded to a server.

<!DOCTYPE html>
<html>

<head>
   <meta charset="utf-8">
    <title>Total </title>
      <link type="text/css" rel="stylesheet" href="course.css"> 
       <script src="../jquery.js"></script>
        <script src="../jquery-ui.js"></script>

 </head>
 <body>


<?php 
  if ($handle = opendir('../uploads')) 
  {
      while (false !== ($entry = readdir($handle))) 
     {

      if ($entry != "." && $entry != "..") 
      {                

          $real= realpath($entry);


            echo  "<button class='files accordian'>$entry</button>
                     <div class='panel'>";

            echo '<a href="'.$real.'"><button class="current-file" name="sent" value="View-Current-File"><img class="view-file-img" src="../images/magnify.png">View Current File</button></a>';
      }

    }       
 } 

 ?> 
</body>
</html>

This code produces the error "Not Found

The requested URL /Applications/MAMP/htdocs/tutorvid/uploads/Applicatgion Text.pages was not found on this server." but when I check the file is at this location

1 个答案:

答案 0 :(得分:0)

这很有效:根本不需要realpath()

<a href="../uploads/'.$entry'">