fopen(); “Remote host file access not accepted” on a local file?

前端 未结 7 835
-上瘾入骨i
-上瘾入骨i 2020-12-28 17:54

I am using the Tcpdf module and PHP to create dymanic PDF invoices from an ordering system.

The script should then save the invoice into a folder called \"invoices\"

7条回答
  •  误落风尘
    2020-12-28 18:50

    I suggest using the following as Gerd has also suggested but make sure you use an absolute path:

    $pdf->Output(__DIR__ . '/invoices/Delivery Note.pdf', 'F');

    The path must be an absolute path & not a relative path. This PHP bug report explains why: https://bugs.php.net/bug.php?id=28820

    The reason relative paths are not supported with the file:// wrapper comes down to a compromise in how UNC paths are dealt with (and more specifically how / are fuzzily interpreted as \ for windows installations).

    For Example:

    file://foo/bar

    Could be interpreted as a relative URI: foo/bar from the current working directory, OR it could be interpreted as a UNC: \foo\bar (share bar on computer foo).

    For this and a few internal reasons the file:// wrapper is limited to absolute paths when called explicitly. For relative paths either use realpath() {as you did in your report}, or omit the explicit naming of the file wrapper.

    You can then avoid modifying the TCPDF code and worrying about any upgrades replacing your modified code.

提交回复
热议问题