【问题标题】:href Link Stopped Workinghref链接停止工作
【发布时间】:2016-10-06 08:41:32
【问题描述】:

我有一个 href 链接,单击该链接应打开位于该位置的 Excel 文件。它在 Chrome 和 IE9 中运行良好,但从昨天开始就停止运行,尽管没有任何改变。

代码如下所示:

<?php
$file_name="MyFile.xlsx";
$folder_name="CurrentFolder" . "/";
$file_path='D:/AllFiles/';
$link1=$file_path. $folder_name. $file_name;
?>

<a href="<?php echo $link1 ?>" target=_blank>
    <div style="height:100%;width:100%"> 
                <?php echo "$link1"; ?>
    </div>
</a>

编辑:

这是一些 httpd.conf 文件:

<Directory "c:/wamp/www/">
    Require local
</Directory>

<Directory "c:/wamp/www/site1/">
    Require all granted
 </Directory>

Alias "/ssfiles" "D:/AllFiles/CurrentFolder"
<Directory "D:/AllFiles/CurrentFolder">
    Require all granted
</Directory>

【问题讨论】:

  • 那么最终的链接在浏览器中是什么样子的呢?当您单击它时,您的 http 服务器访问和错误日​​志文件会显示什么?您的浏览器开发控制台为请求显示了什么? “停止工作”到底是什么意思?如果单击它,究竟会发生什么?
  • 我认为D变成d
  • 嗨 Olivia,我猜D:/AllFiles/..... 不在您的 DocumentRoot 文件夹中,因此 Apache 无法访问。
  • @jhmckimm 抱歉,这不是真的,它不是必需的。
  • @arkascha Line 3 是我在本地检查的,但我错误地多指了一个 '。我的主要论点是使用&lt;?= ?&gt; 标签。看来我一直都错了。

标签: php html href


【解决方案1】:

因为D:/AllFiles/CurrentFolder 文件夹位于 DocumentRoot 文件夹之外,Apache 不允许访问它。我的意思是当用户点击你创建的链接时,Apache 看到一个文件夹,它没有被告知它是否允许访问并且没有访问权限。

您需要为存储在 DocumentRoot 之外的文件夹创建别名,以便 Apache 知道它可以访问它们,以及它们的名称(别名)以及允许谁请求数据。

Alias "/ssfiles" "D:/AllFiles/CurrentFolder"
<Directory "D:/AllFiles/CurrentFolder">
    Require all granted
</Directory>

然后更改代码以使用您创建的别名,然后 apache 看到从 domain.tld/ssfiles/anyfilename.ext 请求的任何内容都将尝试从 D:/AllFiles/CurrentFolder 提供服务器

<?php
$spreadsheet_alias  = 'ssfiles/';
$file_name          = 'MyFile.xlsx';
$link1= $spreadsheet_alias. $file_name;
?>    
<a href="<?php echo $link1 ?>" target=_blank>
    <div style="height:100%;width:100%"> 
        <?php echo "$link1"; ?>
    </div>
</a>

PS:这可能是因为我们修复了 this previous question 中的某些内容

【讨论】:

  • 我在 httpd.conf 中进行了更改并重新启动了 Apache,但现在 Apache 没有重新启动。我将别名部分放在前几天添加的其他目录部分下。
  • 您最好显示一些httpd.conf 将该区域添加到您的问题中
  • 我认为问题是我使用的路径在虚拟服务器上不存在。当我在服务器上的 cmd 中执行 httpd.exe -t 时,我收到 Path Invalid 错误。
猜你喜欢
  • 2011-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-06
  • 1970-01-01
  • 2014-01-04
  • 2019-10-21
相关资源
最近更新 更多