本文整理汇总了PHP中KTUtil::safeShellString方法的典型用法代码示例。如果您正苦于以下问题:PHP KTUtil::safeShellString方法的具体用法?PHP KTUtil::safeShellString怎么用?PHP KTUtil::safeShellString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KTUtil
的用法示例。
在下文中一共展示了KTUtil::safeShellString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getMimeTypeFromFile
/**
* Try well-defined methods for getting the MIME type for a file on disk.
* First try PECL's Fileinfo library, then try mime_content_type() builtin.
* If neither are available, returns NULL.
*
* @param string file on disk
* @return string mime time for given filename, or NULL
*/
function getMimeTypeFromFile($sFileName)
{
if (extension_loaded('fileinfo')) {
// NOTE: fileinfo doesn't like all magic files. ensure it is pointing to a compatible one if it does not work.
// first check the path in the stack
$defaultMagicPath = KT_DIR . '/../php/extras/magic';
$defaultMagicPath = realpath($defaultMagicPath);
// if not available, attempt path from config
if ($defaultMagicPath === false) {
$oKTConfig =& KTConfig::getSingleton();
$defaultMagicPath = $oKTConfig->get('magicDatabase');
if (!file_exists($defaultMagicPath)) {
$defaultMagicPath = false;
}
}
// attempt file info if magic file is resolved
if ($defaultMagicPath) {
$res = @finfo_open(FILEINFO_MIME, $defaultMagicPath);
$sType = @finfo_file($res, $sFileName);
// saw mention that finfo_file() can return empty string under windows
if (empty($sType)) {
$sType = false;
}
}
}
if (!$sType && OS_UNIX) {
if (file_exists('/usr/bin/file')) {
$aCmd = array('/usr/bin/file', '-bi', $sFileName);
$sCmd = KTUtil::safeShellString($aCmd);
$sPossibleType = @exec($sCmd);
if (preg_match('#^[^/]+/[^/*]+$#', $sPossibleType)) {
$sType = $sPossibleType;
}
}
}
if ($sType) {
$iSpacePos = strpos($sType, ' ');
if ($iSpacePos !== false) {
$sType = substr($sType, 0, $iSpacePos);
}
return preg_replace('/;.*$/', '', $sType);
}
return null;
}
示例2: array
<?php
require_once "../../../config/dmsDefaults.php";
require_once KT_LIB_DIR . "/util/ktutil.inc";
$aSource = array(array('unzip', "-q", "-j", "-n", "-d", '/tmp', '5 July 2005 Pricelist - Rectron(cpt).zip'), array('unzip', "-q", "-j", "-n", "-d", '/tmp', "5'th July 2005 Pricelist - Rectron(cpt).zip"), array('echo', ''), array('echo', ' '));
$aExpectedResults = array("'unzip' '-q' '-j' '-n' '-d' '/tmp' '5 July 2005 Pricelist - Rectron(cpt).zip'", "'unzip' '-q' '-j' '-n' '-d' '/tmp' '5'\\''th July 2005 Pricelist - Rectron(cpt).zip'", "'echo' ''", "'echo' ' '");
$aResults = array();
foreach ($aSource as $aArgs) {
$aResults[] = KTUtil::safeShellString($aArgs);
}
if ($aResults === $aExpectedResults) {
print "Success!\n";
} else {
print "Failure!\n";
print "Received: " . print_r($aResults, true) . "\n";
print "Expected: " . print_r($aExpectedResults, true) . "\n";
}