Get file url schema

2019-09-14 20:47发布

问题:

How do I show the user a previously uploaded file that is stored on the website's server (I am aware uploaded files should be stored on a different server) when I know the path? To explain; below in my code I have created a button inside an element and I am trying to get it to display the relevant file to the user by putting the relevant url in the element shows the user the file they need to see.

<!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("../uploads/".$entry);


            echo  "<button class='files accordian'>$entry $real</button>
                     <div class='panel'>
                        <p>$real</p>";
            echo '<a href="WHAT WOULD GO IN HERE?"><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> 

回答1:

I think this should be enough for you,

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


回答2:

Looks like you are using $real before you define it.

echo  "<button class='files accordian'>$entry $real</button>";
$real=realpath("../uploads/".$entry);

This should be the other way.

If you still have problems, do this and check the result.

var_dump(realpath("../uploads/".$entry));