How can I determine the maximum filename length on a linux box?
Preferred in PHP programming language.
How can I determine the maximum filename length on a linux box?
Preferred in PHP programming language.
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
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.
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.
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.