如何在 php 和 Linux 中安全地访问根目录之外的文件?

问题描述 投票:0回答:0

我有以下代码正在

Red Hat Enterprise Linux (Apache Web server)
上运行。我想访问位于根目录之外的文件。

$link_options = [];
echo "<pre>"; print_r($file_location); echo "</pre>";   // Line Z 
foreach ($file_location->files as $current_file) {
    $file_labels[] = $current_file->label;
    if ('HYPERLINK' == $current_file->label && substr($current_file->pattern, 0, 2) === 'A:') {  // Line A
        $file_pattern = str_replace('\\', '/', $current_file->pattern); 
        $link_options[] = [$current_file->label, str_replace('A:', '/mnt/good/a', $file_pattern)];
        continue;
}

if (1 == sizeof($link_options)) {
    $link_url = $link_options[0][1];   // Line B
}

Line Z
打印以下内容,表明我正在尝试访问 Redhat Enterprise Linux 之外的文件(根目录之外)。

Array
(
    [0] => DiagramFile Object
        (
            [label] => HYPERLINK
            [pattern] => A:\WORLD\Morning\Materials\Morning.docx
        )

)

问题陈述:

Line A
上面的代码中建议进行哪些更改,以便我可以安全地访问 Windows 中位于 Linux 根目录之外的文件?

据我了解,我无法直接链接到网站根目录之外的任何内容。这是安全问题。我需要遵循哪些安全措施?

php linux apache document-root
© www.soinside.com 2019 - 2024. All rights reserved.