5

How can I determine the maximum filename length on a linux box?

Preferred in PHP programming language.

Allan Bowe
  • 12,306
  • 19
  • 75
  • 124
prinzdezibel
  • 11,029
  • 17
  • 55
  • 62

5 Answers5

6

You want pathconf or fpathconf, which are not exposed (yet) in PHP. (When they are, they'll probably be posix_pathconf.)

You may also shell out to getconf, a command-line utility interface to the same functionality. Try this on your system:

$ getconf NAME_MAX /tmp

$ getconf PATH_MAX /tmp

pilcrow
  • 56,591
  • 13
  • 94
  • 135
5

there's no need to programatically determine it. it's 255 bytes.

edit: you can have longer filenames on a very few file systems (reiser, i believe), but if you stick to 255 your app will be usable on any linux installation.

glomad
  • 5,539
  • 2
  • 24
  • 38
4

The maximum file length for most linux file systems is 255. You're probably best off using that as a generic constant and modifying to fit your known file system in linux. Here's a nice comparison of the file systems that might be used. Max file length is listed there.

Randolpho
  • 55,384
  • 17
  • 145
  • 179
1

You can use the constant PHP_MAXPATHLEN

André Sousa
  • 428
  • 5
  • 9
0

I think you could use realpath(). I'm not sure best approach, but for example:

$maxlen=264-strlen(realpath('index.php')));

264 is 255(max path lim) + 9 ('index.php' len). So substracting current path length from limit gives you max current path length.

Thinker
  • 14,234
  • 9
  • 40
  • 55