當前位置: 首頁>>代碼示例>>PHP>>正文


PHP KTUtil::safeShellString方法代碼示例

本文整理匯總了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;
 }
開發者ID:sfsergey,項目名稱:knowledgetree,代碼行數:52,代碼來源:mime.inc.php

示例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";
}
開發者ID:5haman,項目名稱:knowledgetree,代碼行數:17,代碼來源:testSafeShellString.php


注:本文中的KTUtil::safeShellString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。