In PHP, how can I open a file that has special characters in the name?

在PHP中,如何打开名称中包含特殊字符的文件?

The name is similar to iPad|-5542fa5501f31.log

该名称类似于iPad | -5542fa5501f31.log

Per another forum, I've tried:

在另一个论坛上,我尝试过:

$logid = str_replace(" ", "\x20", $_GET['logid']);
$logid = str_replace("|", "\x7C", $logid);

To massage the name, but that doesn't work for me either.

按摩这个名字,但这对我也不起作用。

I've also already tried:

我也试过了:

$dst_file = escapeshellarg($dst_file);

And of course started out with just straight:

当然,从直接开始:

$logid = $_GET['logid'];

The initial file was created by a PHP script on a Linux system. I'm confused why a PHP script can write a file name like that, but can't open it for reading.

初始文件是由Linux系统上的PHP脚本创建的。我很困惑为什么PHP脚本可以写这样的文件名,但无法打开它进行阅读。

Here's my current code:

这是我目前的代码:

$logid = str_replace(" ", "\x20", $_GET['logid']);
$logid = str_replace("|", "\x7C", $logid);
$logdate = str_replace("-", "/", $_GET['date'])."/";
$dst_file = $uploads_dir.$logdate.$logid.'.log';

// read the data from the log file
echo "<pre>\n";
if (file_exists($dst_file)) {
    $file_handle = fopen($dst_file, "r");
    while (!feof($file_handle)) {
        $line = fgets($file_handle);
        if (strlen($line) < 3) continue;
        echo $line;
    }
    fclose($file_handle);
} else {
    echo $dst_file." does not exist\n";
}
echo "</pre>\n";

3 个解决方案

#1


The only thing I found was to rename the file then open. The problem is no PHP functions so I tried system commands. None worked. The ftp RNTO command will rename it. But it would be much better to filter out "special characters" when the file is saved.

我发现的唯一的事情是重命名文件然后打开。问题是没有PHP函数所以我尝试了系统命令。没有用。 ftp RNTO命令将重命名它。但是在保存文件时过滤掉“特殊字符”会好得多。

更多相关文章

  1. php 读取文本文件
  2. 如何将项添加到json文件格式化数组
  3. 如何实现分布式文件上传解决方案?
  4. phpstorm取消自动保存并标识修改的文件为星星标记
  5. PHP通过系统命令执行Python脚本
  6. 在HTTP 1.0中,状态码401的含义是什么;如果返回“找不到文件”的提
  7. thinkphp整合系列之tcpdf类生成pdf文件
  8. PHP常用的文件操作函数集锦
  9. PHP邮件脚本占用了大量资源

随机推荐

  1. angularjs是怎么为ng-click事件传递参数
  2. WPF核心的技术--数据绑定
  3. 比如说我们要从用户表customer和用户订单
  4. MVC 5限制所有HTTP请求必须是POST方式
  5. lambda表达式进行对象结合操作的实例详解
  6. 最新开源DBLayer的详细介绍
  7. IIS中出现了时间格式转换错误该如何解决?
  8. C#中匿名委托以及Lambda表达式的实例详解
  9. WPF实现简单的进度条怎么做?
  10. Oracle Clob字段过长保存出错改如何解决?