简体   繁体   English

在linux / freebsd / macosx上使用PHP查找实用程序的安装路径

[英]Finding the install path of a utility with PHP on linux/freebsd/macosx

I have a PHP code block I've written that uses imagemagick's convert program (called through exec()) to create thumbnails of uploaded images (originally we tried using the PHP module calls, but kept running into memory errors). 我写了一个PHP代码块,它使用imagemagick的转换程序(通过exec()调用)来创建上传图像的缩略图(本来我们尝试使用PHP模块调用,但一直遇到内存错误)。

Of course to do this I have to have the full path to convert, which varies from system to system (on my mac it's at /opt/local/bin/convert). 当然,要做到这一点,我必须拥有完整的转换路径,该路径因系统而异(在我的Mac上为/ opt / local / bin / convert)。 I've been just looking it up on the server and setting it in a constant, but this is often less than ideal. 我一直在服务器上查找它并将其设置为常数,但这通常不理想。

My question is, is there a way to programmatically lookup the install path of convert? 我的问题是,有没有办法以编程方式查找convert的安装路径? I can then just store it in the database or something for quick lookup. 然后,我可以将其存储在数据库中或进行快速查找。

If "convert" is in the include path for a user, 如果用户的包含路径中包含“转换”,

 $path = `which convert`; 

should find it. 应该找到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM