dongzheng8463 2017-10-13 20:55
浏览 28

在Webroot上访问和交付XML文件

I'm trying to load an appcast xml file from a php file, The xml contains a file path used to display a changelog.html & gives a download path to a file. Normally, I don't want browsers to be able to access this stuff, so, the xml file, changelog & the file are all together in folder above the web root directory. The php file is inside of the webroot.

Here's my php code:

$filename = "./home/myaccountusername/folder1/folder2/appcast.xml";
    if (!file_exists ($filename)) throw new Exception("File not found");

    // Set the content type to xml
    header('Content-Type: text/xml');
    header('Content-Disposition: attachment; filename="' . basename($filename) . '"');
    header('Content-Length: ' . filesize($filename));
    // Tell the user-agent (Stacks) not to cache the file
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    // Flush the output buffer
    ob_clean();
    flush();
    // Read the data and send the file
    //throw new Exception("FileName: " . $filename);
    readfile($filename);
    exit; 

It's throwing exception: File not found

How do I write the paths to look above the webroot & when passed to my final display interface, allows the changelog.html to be opened & the file to be downloaded?

Note: I've tried the beginning of the path to be /home... and home... & even ../../../folder1/ ...

Is this possible to set up in php? Can't figure it out.

Update1: Here's a tree of server:

- public_html 
  - appcastsecure  
    - productfolder  
     - appcast.xml  
     - changelog.html  
     - productzipfile.zip  

  - company_folder  
      - secureappcast  
         - appcastfile.php  (start here for pathing)  

I'm using DIR in appcastfile.php which gives path to appcast.xml:

$filename = /home/userdir/public_html/company_folder/secureappcast/../../appcastsecure/productfolder/appcast.xml

My problem is appcast.xml is pushed to clients on their server, so I can't figure out how to set up pathing in appcast.xml so it will point to changelog & productzipfile on my server (all are outside of public_html)

  • 写回答

1条回答 默认 最新

  • dps43378 2017-10-14 09:39
    关注

    Firstly, the one in your example is trying to access the a folder relative to the current directory...

    $filename = "./home/myaccountusername/folder1/folder2/appcast.xml";
    

    The first dot shouldn't be there anyway.

    If you want to access a file that is relative to a directory, you can use __DIR__, which gives the directory of the script your currently in. This then depends on where the file your trying to access is relative to the current script. So

    $filename = __DIR__."/../appcast.xml";
    

    Is a file in the directory above the one containing this script. You will have to adjust this depending on your particular requirements.

    评论

报告相同问题?

悬赏问题

  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了