本文介绍了PHP为什么找不到长文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文件夹内,我有一个名为

`111-aaaaaa aa aaaa-,._aaaaaaa;  aaaaaaaa, aa aaaaaaaaaa, aaaaaaaaa aaaaaaaa.   03.01.10.  38.38 aaaaa.txt`

当我使用PHP浏览该目录(或尝试读取该文件)时:

when I browse that directory with PHP (or trying to read that file):

var_dump(glob('MyFolder/*'));exit;

找不到该文件.什么问题? (如果我缩短文件名,则可以找到它.我在Windows上)

It can't find that file. What's problem? (if I shorten the filename, then it becomes findable. I am on windows)

推荐答案

尤其是Windows,在其原始Win32 API中文件名限制非常短.在此处在SO处讨论

Windows in particular has a very short file name limit in its original Win32 API. This general problem is discussed here at SO.

在Win32的绝对路径中最多可以使用260个字符.在其他平台上,还有其他限制,但是至少要有512个字符,而且并非闻所未闻.

At most about 260 characters can be used in an absolute path on Win32. On other platforms there are other limits, but at least 512 characters is to be expected and more is not unheard of.

但是,Windows实际上可以具有更长的文件名(很明显,因为文件名在计算机上).这可以通过使用更新的Windows API来实现.不幸的是,据我所知,标准的PHP没有使用此API.

However, Windows actually can have longer filenames (obviously, as you have them on your computer). This works by using a newer Windows API. Unfortunately, standard PHP does not use this API, as far as I know.

有一个PHP的修改版本,该版本使用了较新的Windows API 在Github上.

There is a modified version of PHP which makes use of this newer Windows API over at Github.

使用较新的API的另一个好处是,它在文件名中还支持Unicode字符.

Another benefit from using that newer API is that it also supports Unicode characters in the file names.

这篇关于PHP为什么找不到长文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 13:45