elgg 获取文件图标地址的方法
前端之家收集整理的这篇文章主要介绍了
elgg 获取文件图标地址的方法,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
过程如下:
首先,实体保存的时候用这个方法(系统本身的):
比如有一个Activity类,继承自ElggObject,创建了一个它的实例 activity,
<div class="codetitle"><a style="CURSOR: pointer" data="55082" class="copybut" id="copybut55082" onclick="doCopy('code55082')"> 代码如下:
<div class="codebody" id="code55082">
// Now see if we have a file icon
if ((isset($_FILES['icon'])) && (substr_count($_FILES['icon']['type'],'image/'))) {
$prefix = "activity/".$activity->guid;
$filehandler = new ElggFile();
$filehandler->owner_guid = $activity->owner_guid;
$filehandler->setFilename($prefix . ".jpg");
$filehandler->open("write");
$filehandler->write(get_uploaded_file('icon'));
$filehandler->close();
$thumbtiny = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(),25,true);
$thumbsmall = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(),40,true);
$thumbmedium = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(),100,true);
$thumblarge = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(),200,false);
if ($thumbtiny) {
$thumb = new ElggFile();
$thumb->owner_guid = $activity->owner_guid;
$thumb->setMimeType('image/jpeg');
$thumb->setFilename($prefix."tiny.jpg");
$thumb->open("write");
$thumb->write($thumbtiny);
$thumb->close();
$thumb->setFilename($prefix."small.jpg");
$thumb->open("write");
$thumb->write($thumbsmall);
$thumb->close();
$thumb->setFilename($prefix."medium.jpg");
$thumb->open("write");
$thumb->write($thumbmedium);
$thumb->close();
$thumb->setFilename($prefix."large.jpg");
$thumb->open("write");
$thumb->write($thumblarge);
$thumb->close();
}
}
。getIcon是entities.
$url = trigger_plugin_hook('entity:icon:url',$entity->getType(),array('entity' => $entity,'viewtype' => $viewtype,'size' => $size),$url);
的start.
然后在start.