gpt4 book ai didi

当文件名中有 +(加号)时,PHP file_get_contents() 不起作用

转载 作者:搜寻专家 更新时间:2023-10-31 21:07:06 25 4
gpt4 key购买 nike

我有几个名称中带有加号的文件,但我似乎无法打开它们,因为该函数将其解释为空格。

示例:

File name: Report_Tue-Jun-02-2015-14:11:04-GMT+0200-(W.-Europe-Daylight-Time).html

当我尝试打开它时:

Warning: file_get_contents(/cores/Report_Tue-Jun-02-2015-14:11:04-GMT 0200-(W.-Europe-Daylight-Time).html) [function.file-get-contents]: failed to open stream: No such file or directory in .... on line 150

这是我的代码:

$file = $_GET['FILE'];  
$file = str_replace('+', '%2B', $file);
$content = file_get_contents($file);

有什么想法/解决方案吗?

最佳答案

以下方法对我来说效果很好。

<?

# File name: Report_Tue-Jun-02-2015-14:11:04-GMT+0200-(W.-Europe-Daylight-Time).html

# Method 1.

$file = 'Report_Tue-Jun-02-2015-14:11:04-GMT+0200-(W.-Europe-Daylight-Time).html';

$data = file_get_contents($file);

print($data);

# Method 2.

$data = file_get_contents('Report_Tue-Jun-02-2015-14:11:04-GMT+0200-(W.-Europe-Daylight-Time).html');

print($data);
?>

关于当文件名中有 +(加号)时,PHP file_get_contents() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30612685/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com