这篇文章主要为大家详细介绍了elgg 获取文件图标地址的简单示例,具有一定的参考价值,可以用来参考一下。
感兴趣的小伙伴,下面一起跟随四海网的小编小韵来看看吧!
过程如下:代码如下:
// 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,25, true);
$thumbsmall = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(),40,40, true);
$thumbmedium = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(),100,100, true);
$thumblarge = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(),200,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();
}
}
代码如下:
/**
* 获取图标
* This hooks into the getIcon API and provides nice user icons for users where possible.
*
* @param string $hook 钩子名
* @param string $entity_type 实体类型
* @param string $returnvalue 图片url地址
* @param unknow $params 参数表列
* @return string $url 图片url地址
*/
function activity_activityicon_hook($hook, $entity_type, $returnvalue, $params) {
global $CONFIG;
if ((!$returnvalue) && ($hook == 'entity:icon:url') && ($params['entity'] instanceof Activity)) {
$entity = $params['entity'];
$type = $entity->type;
$viewtype = $params['viewtype'];
$size = $params['size'];
if ($icontime = $entity->icontime) {
$icontime = "{$icontime}";
} else {
$icontime = "default";
}
$filehandler = new ElggFile();
$filehandler->owner_guid = $entity->owner_guid;
$filehandler->setFilename("activity/" . $entity->guid . $size . ".jpg");
if ($filehandler->exists()) {
$url = $CONFIG->url . "pg/activityicon/{$entity->guid}/$size/$icontime.jpg";
return $url;
}
}
}
本文来自:http://www.q1010.com/173/13730-0.html
注:关于elgg 获取文件图标地址的简单示例的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。
关键词:
四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。