contentDelivery.php 782 B

123456789101112131415161718192021222324
  1. <?php
  2. //這個 PHP 只限用於載入用家自己的資料。要載入別人的帖子請不要用這個 PHP
  3. include_once("../auth.php");//避免有人直接 Call 此 PHP 檔
  4. $dataStorage = $sysConfigDir . '/userdata/' . $_SESSION['login'] . "/";
  5. if (isset($_GET['filename']) && $_GET['filename'] != ""){
  6. $filename = $_GET['filename'];
  7. $filename = str_replace("../","",$filename); //避免被退出
  8. //檢查此檔案是否存在
  9. if (file_exists($dataStorage . $filename)){
  10. echo realpath($dataStorage . $filename);
  11. header('X-Sendfile: ' . realpath($dataStorage . $filename));
  12. header('Content-Type: ' . mime_content_type(realpath($dataStorage . $filename)));
  13. }else{
  14. //檔案不存在
  15. http_response_code(404);
  16. die();
  17. }
  18. }else{
  19. http_response_code(400);
  20. die();
  21. }
  22. ?>