PHP不允许加载本地资源 [英] PHP Not allowed to load local resource

查看:69
本文介绍了PHP不允许加载本地资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定为什么会出现以下错误:

I am not sure why I am getting the following error:

Not allowed to load local resource: file:///D:/CargoDocsPDFs/0000024606//NAM3112358.pdf

我正在使用下面的功能来创建一个表格,该表格带有指向pdf文件的链接,用户只需单击即可下载:

I am using the function below to create a table with links to pdf files a user can simply click to download:

<?php
function return401KDocs()
{
$dir = "D:/CargoDocsPDFs/0000024606/";
$ffs = scandir($dir);

echo "<table class='table table-bordered display nowrap'>";
echo "<thead>";
echo "<tr>
        <th style='width:300px;'>File Name</th>
        <th style='width:100px;'>Upload Date</th>
        <th style='width:25px;'>File Size</th>
        <th style='width:100px;'>Delete</th>
      </tr>";
echo "</thead>";
echo "<tbody>";
foreach($ffs as $ff)
{
    if($ff != '.' && $ff != '..' && preg_match('#(pdf|doc|docx|xls|xlsx|PDF)$#',$ff))
    {                       
        $filesize = filesize($dir . '/' . $ff); 
        echo "<tr><td><a download href='$dir/$ff'>$ff</a></td><td>" . 
        date('m.d.y - g:i A', filemtime($dir . '/' . $ff)) . 
        "</td><td>" . round(($filesize / 1024), 2) . " kb</td>
        <td><a href='#' class='delete401KFile' data-file='".$ff."'>Delete</a></td></tr>";
    }
}
echo "</tbody>";
echo "</table>";
}    
?>

使用上述功能可以打印出表格,并且可用文件是用户应该能够单击以下载文件的链接.但是主题错误消息禁止我使用该消息.

Using the above function prints out a table, and the available files are links that a user should be able to click to download the file. But I am prohibited by the subject error message.

我找到了此链接: jQuery不允许加载本地资源

但是我不能使用该链接,因为它与使用AJAX调用有关.我正在尝试使用PHP完成此任务.

But I cannot use that link as it is in regards to using an AJAX call. I am trying to accomplish this task with PHP.

推荐答案

我的回答是因为要点而无法发表评论,所以请不要投反对票.

I made an answer coz wasn't able to comment because of the points, so please don't negative vote.

您不应从本地文件系统加载文件.您需要将其托管在您的应用中,然后将其从网络服务器上加载.

You shouldn't load files off a local filesystem. You need to have it hosted with your app and load it off the web server.

您将永远无法在客户端上直接显示存储文件夹(C或D驱动器)中的文件.浏览器真正可以了解的唯一信息是:

You will never be able to directly display files on the client that are in your storage folder (C or D drives). The only thing browsers can actually get at are:

  1. 公用文件夹下的实际内容
  2. 通过index.php(您的应用程序)调用的代码

因此,您需要将文件存储在(服务器的)公共文件夹中的某个位置

So, you would need to store your files somewhere in the public folder (of the server)

您可以通过此链接获得一些帮助: https://webmasters.stackexchange.com/questions/53870/cannot-load-local-resource

You can get some help with this link: https://webmasters.stackexchange.com/questions/53870/cannot-load-local-resource

这篇关于PHP不允许加载本地资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆