duanpu4143 2012-06-27 10:13
浏览 24
已采纳

下载链接以使用PHP中的href下载XML文件

need a small basic help, I am creating a XML file on the fly using the parameters submitted in the form by the user. Once the form is submitted, I am jumping into PHP code and there I wanted to give a href link to Download/Display the created XML file.

This is my example code:

<?php

$outputForm = 1;   

if(isset($_POST['submit'])){
$outputForm = 0

//Function to generate XML file which works as expected, so that XML file is there
createXML($folderPath, $albumName, $dateOfEntry);

//My XML file is named as albumName.xml and stored in the folderPath as specified
echo '<a href = "' .  $folderPath . $albumName. '.xml' . '">XML FILE</a>';
}
 else{
            $outputForm = 1;
        }
        if($outputForm == 1)
        {     
       //Here follows my input form
     <?php
       }
     ?>

FYI: 
$folderPath = 'c:/htdocs/output/';
Therefore:
$folderPath . $albumName = 'c:/htdocs/output/jessi';
In this example xml file name:
jessi.xml

I can see the href link in the output but it does nothing when I click on it. I can also see the fullpath to the xml file when I move my cursor over the 'XML FILE' link.

Any ideas how I can embed a href link in the php script to either Download/Display the XML file.

Thanks

  • 写回答

1条回答 默认 最新

  • dqrnskni67375 2012-06-27 10:49
    关注

    Issue is, you are running your code by accessing to it using http protocol (whether on your local server or remote) and the file you are trying to access is local and you are accessing your local xml file using File URI Scheme So, browser is restricting you to access that file, maybe for some security reason. If you try to access a file by opening a html file directly in browser (not by running it from your localhost) you will be able to access that file location using that link, browser won't restrict you. But you won't be able to execute the php code.

    So, You can use relative path or reference to file from your localhost's relative path, use http URI scheme for this and browser won't restrict you from opening a local file.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 关于多单片机模块化的一些问题
  • ¥30 seata使用出现报错,其他服务找不到seata
  • ¥35 引用csv数据文件(4列1800行),通过高斯-赛德尔法拟合曲线,在选取(每五十点取1点)数据,求该数据点的曲率中心。
  • ¥20 程序只发送0X01,串口助手显示不正确,配置看了没有问题115200-8-1-no,如何解决?
  • ¥15 Google speech command 数据集获取
  • ¥15 vue3+element-plus页面崩溃
  • ¥15 像这种代码要怎么跑起来?
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection