Why can't PHP find long filenames?
Asked Answered
A

4

5

inside a Folder I have a file, named

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

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

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

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

Angwantibo answered 9/2, 2015 at 10:27 Comment(2)
On Windows you have maximum path length limitation: msdn.microsoft.com/en-us/library/windows/desktop/…Let
@TOBIASK, I have such filename and that's all. SO, if you know, post solution, if not, dont OFF-Topic.Angwantibo
W
6

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

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.

(For instance, in GNU HURD, there effectively is no limit to file lengths, even though the underlying file system may impose a limit.)

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.

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

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

Warrigal answered 9/2, 2015 at 10:29 Comment(3)
Hi! Unfortunately, I installed the extension you pointed for longer path supports, and it still bugs. I tested fopen("wfio://SHORTER_PATH") and it works correctly, but not my long path. Have any idea ?Longe
@MasterDJon, not really. Are you using fullpath as the docs say one must? Other than that ... not really, sorry.Warrigal
Yes, I was using fullpath (I said "was" because I changed my backup method to store path in a file and rename them by a sequential number)Longe
Y
2

Starting with PHP 7.1 long and UTF-8 paths on Windows are supported directly in the core.

Cheers.

Yonder answered 10/8, 2016 at 18:26 Comment(3)
While Unicode (not UTF-8) paths seem to be supported, long paths are still not.Dresser
Not sure what you mean. UTF-16? Things are literally what was told - UTF-8 and long path. Please check UPGRADING and report issues if you see some. Thanks.Yonder
Sometimes, no matter what, even newer PHP versions would not work with long paths. But, occasionally, the reason might be different from what we think. For example, there was a bug about PHP not being able to work with paths containing certain types of symboling links (fixed as of 7.3.10 and newer), which may coincide with the use of long paths. Anyway, the last resort is always using junction links: mklink /J "Short\Path" "Your\Very\Long\Path".Lido
B
1

try scandir() it's show list file in array.

Bioplasm answered 9/2, 2015 at 10:33 Comment(0)
I
1

Sorry to revive an old thread. I've found that the WFIO PHP module still seems useful together with extended-length paths format (\\?\) to support long paths (up to 1024) in Windows.

# Local
wfio://\\\\?\C:\path

# Network
wfio://\\\\?\UNC\server\path
Idel answered 25/3, 2024 at 10:57 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.