Programmatically determine maximum filename length

走远了吗. 提交于 2019-12-22 06:23:59

问题


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

Preferred in PHP programming language.


回答1:


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




回答2:


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.




回答3:


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.




回答4:


You can use the constant PHP_MAXPATHLEN




回答5:


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.



来源:https://stackoverflow.com/questions/1178417/programmatically-determine-maximum-filename-length

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!