Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 出入境及;在Webroot上交付XML文件_Php_Xml - Fatal编程技术网

Php 出入境及;在Webroot上交付XML文件

Php 出入境及;在Webroot上交付XML文件,php,xml,Php,Xml,我试图从php文件加载appcast xml文件,xml包含一个用于显示changelog.html的文件路径&提供文件的下载路径。通常,我不希望浏览器能够访问这些内容,因此,xml文件、changelog和文件都位于web根目录上方的文件夹中。php文件位于webroot内部 以下是我的php代码: $filename = "./home/myaccountusername/folder1/folder2/appcast.xml"; if (!file_exists ($filenam

我试图从php文件加载appcast xml文件,xml包含一个用于显示changelog.html的文件路径&提供文件的下载路径。通常,我不希望浏览器能够访问这些内容,因此,xml文件、changelog和文件都位于web根目录上方的文件夹中。php文件位于webroot内部

以下是我的php代码:

$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; 
它正在引发异常:找不到文件

我如何编写路径以查看webroot上方&当传递到最终显示界面时,允许打开changelog.html并下载文件

注意:我已经尝试了路径的开始是/家。。。和家…&偶数../../../folder1/

这可以在php中设置吗?我想不出来

更新1: 以下是服务器的目录树:

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

  - company_folder  
      - secureappcast  
         - appcastfile.php  (start here for pathing)  
我在appcastfile.php中使用了DIR,它给出了appcast.xml的路径:

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

我的问题是appcast.xml被推送到客户端的服务器上,所以我不知道如何在appcast.xml中设置路径,这样它就会指向我服务器上的changelog和productzipfile(都在public_html之外)

首先,您的示例中的一个尝试访问相对于当前目录的a文件夹

$filename = "./home/myaccountusername/folder1/folder2/appcast.xml";
第一个点无论如何都不应该在那里

如果要访问与目录相关的文件,可以使用
\uuuuu DIR\uuuuu
,这将提供当前所在脚本的目录。这取决于您试图访问的文件相对于当前脚本的位置。所以

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

是包含此脚本的目录上方目录中的文件。您必须根据您的具体要求进行调整。

Hi@Nigel,请参阅上面的更新1,希望这能解释我的意图。