Get file url schema

旧时模样 提交于 2019-12-12 04:35:58

问题


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));


来源:https://stackoverflow.com/questions/44400055/get-file-url-schema

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!