本文整理汇总了PHP中Toolbox::getMime方法的典型用法代码示例。如果您正苦于以下问题:PHP Toolbox::getMime方法的具体用法?PHP Toolbox::getMime怎么用?PHP Toolbox::getMime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Toolbox
的用法示例。
在下文中一共展示了Toolbox::getMime方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: convertTagToImage
/**
* Convert tag to image
*
* @since version 0.85
*
* @param $content_text text content of input
* @param $force_update force update of content in item (false by default
* @param $doc_data array of filenames and tags
*
* @return nothing
**/
function convertTagToImage($content_text, $force_update = false, $doc_data = array())
{
global $CFG_GLPI;
$matches = array();
// If no doc data available we match all tags in content
if (!count($doc_data)) {
$doc = new Document();
preg_match_all('/' . Document::getImageTag('(([a-z0-9]+|[\\.\\-]?)+)') . '/', $content_text, $matches, PREG_PATTERN_ORDER);
if (isset($matches[1]) && count($matches[1])) {
$doc_data = $doc->find("`tag` IN('" . implode("','", array_unique($matches[1])) . "')");
}
}
if (count($doc_data)) {
foreach ($doc_data as $id => $image) {
// Add only image files : try to detect mime type
$ok = false;
$mime = '';
if (isset($image['filepath'])) {
$fullpath = GLPI_DOC_DIR . "/" . $image['filepath'];
$mime = Toolbox::getMime($fullpath);
$ok = Toolbox::getMime($fullpath, 'image');
}
if (isset($image['tag'])) {
if ($ok || empty($mime)) {
// Replace tags by image in textarea
$img = "<img alt='" . $image['tag'] . "' src='" . $CFG_GLPI['root_doc'] . "/front/document.send.php?docid=" . $id . "&tickets_id=" . $this->fields['id'] . "'/>";
// Replace tag by the image
$content_text = preg_replace('/' . Document::getImageTag($image['tag']) . '/', Html::entities_deep($img), $content_text);
// Replace <br> TinyMce bug
$content_text = str_replace(array('>rn<', '>\\r\\n<', '>\\r<', '>\\n<'), '><', $content_text);
// If the tag is from another ticket : link document to ticket
// TODO : comment maybe not used
// if($image['tickets_id'] != $this->fields['id']){
// $docitem = new Document_Item();
// $docitem->add(array('documents_id' => $image['id'],
// '_do_notif' => false,
// '_disablenotif' => true,
// 'itemtype' => $this->getType(),
// 'items_id' => $this->fields['id']));
// }
} else {
// Remove tag
$content_text = preg_replace('/' . Document::getImageTag($image['tag']) . '/', '', $content_text);
}
}
}
}
if ($force_update) {
$this->fields['content'] = $content_text;
$this->updateInDB(array('content'));
}
return $content_text;
}
示例2: moveDocument
/**
* Move a document (files in GLPI_DOC_DIR."/_tmp" dir)
*
* @param $input array of datas used in adding process (need current_filepath)
* @param $filename filename to move
*
* @return boolean for success / $input array is updated
**/
static function moveDocument(array &$input, $filename)
{
global $CFG_GLPI;
$fullpath = GLPI_TMP_DIR . "/" . $filename;
if (!is_dir(GLPI_TMP_DIR)) {
Session::addMessageAfterRedirect(__("Temporary directory doesn't exist"), false, ERROR);
return false;
}
if (!is_file($fullpath)) {
Session::addMessageAfterRedirect(sprintf(__('File %s not found.'), $fullpath), false, ERROR);
return false;
}
$sha1sum = sha1_file($fullpath);
$dir = self::isValidDoc($filename);
$new_path = self::getUploadFileValidLocationName($dir, $sha1sum);
if (!$sha1sum || !$dir || !$new_path) {
return false;
}
// Delete old file (if not used by another doc)
if (isset($input['current_filepath']) && !empty($input['current_filepath']) && is_file(GLPI_DOC_DIR . "/" . $input['current_filepath']) && countElementsInTable('glpi_documents', "`sha1sum`='" . sha1_file(GLPI_DOC_DIR . "/" . $input['current_filepath']) . "'") <= 1) {
if (unlink(GLPI_DOC_DIR . "/" . $input['current_filepath'])) {
Session::addMessageAfterRedirect(sprintf(__('Succesful deletion of the file %s'), $input['current_filename']));
} else {
// TRANS: %1$s is the curent filename, %2$s is its directory
Session::addMessageAfterRedirect(sprintf(__('Failed to delete the file %1$s (%2$s)'), $input['current_filename'], GLPI_DOC_DIR . "/" . $input['current_filepath']), false, ERROR);
}
}
// Local file : try to detect mime type
$input['mime'] = Toolbox::getMime($fullpath);
if (is_writable(GLPI_TMP_DIR) && is_writable($fullpath)) {
// Move if allowed
if (self::renameForce($fullpath, GLPI_DOC_DIR . "/" . $new_path)) {
Session::addMessageAfterRedirect(__('Document move succeeded.'));
} else {
Session::addMessageAfterRedirect(__('File move failed.'), false, ERROR);
return false;
}
} else {
// Copy (will overwrite dest file is present)
if (copy($fullpath, GLPI_DOC_DIR . "/" . $new_path)) {
Session::addMessageAfterRedirect(__('Document copy succeeded.'));
} else {
Session::addMessageAfterRedirect(__('File move failed'), false, ERROR);
return false;
}
}
// For display
$input['filename'] = addslashes($filename);
// Storage path
$input['filepath'] = $new_path;
// Checksum
$input['sha1sum'] = $sha1sum;
return true;
}