【问题标题】:file_exists cannot handle the file name that has spacial characterfile_exists 无法处理具有特殊字符的文件名
【发布时间】:2015-10-26 04:24:21
【问题描述】:

我检查了file_exists 不支持特殊字符。

我的系统需要检查用户提交的文件。并且文件名包含 dash 字符,这使得 Internal Error 500并且用户坚持不更改文件名以使用系统

这是 PHP 代码:

$file_location = $db->user_file_path; // path: /path/to/user/file/file-name.pdf
if(!file_exists($file_location))
{
    // send email to user
}

我该如何处理这种情况?

【问题讨论】:

  • 我试过了,但不适合我
  • 什么是“空间字符”?老实说,破折号并不是那么特别。也许 ASCII 范围之外的连字符之一可能要求您正确编码文件,但这些都不能解释发生了什么。

标签: php


【解决方案1】:

试试realpath

realpath() 函数返回绝对路径名。

此函数删除所有符号链接(如“/./”、“/../”等 '/') 并返回绝对路径名。

realpath() 在失败时返回 FALSE,例如如果文件不存在。

【讨论】:

    猜你喜欢
    • 2022-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多