本文整理汇总了PHP中ElggFile::write方法的典型用法代码示例。如果您正苦于以下问题:PHP ElggFile::write方法的具体用法?PHP ElggFile::write怎么用?PHP ElggFile::write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ElggFile
的用法示例。
在下文中一共展示了ElggFile::write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: form_generate_thumbnail
function form_generate_thumbnail($file, $fieldname)
{
// Generate thumbnail (if image)
$prefix = "file/";
$filestorename = strtolower(time() . $_FILES[$fieldname]['name']);
if (substr_count($file->getMimeType(), 'image/')) {
$thumbnail = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 60, 60, true);
$thumbsmall = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 153, 153, true);
$thumblarge = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 600, 600, false);
if ($thumbnail) {
$thumb = new ElggFile();
$thumb->setMimeType($_FILES[$fieldname]['type']);
$thumb->setFilename($prefix . "thumb" . $filestorename);
$thumb->open("write");
$thumb->write($thumbnail);
$thumb->close();
$file->thumbnail = $prefix . "thumb" . $filestorename;
$thumb->setFilename($prefix . "smallthumb" . $filestorename);
$thumb->open("write");
$thumb->write($thumbsmall);
$thumb->close();
$file->smallthumb = $prefix . "smallthumb" . $filestorename;
$thumb->setFilename($prefix . "largethumb" . $filestorename);
$thumb->open("write");
$thumb->write($thumblarge);
$thumb->close();
$file->largethumb = $prefix . "largethumb" . $filestorename;
}
}
}
示例2: CreateLTIGroup
function CreateLTIGroup($user, $name, $context_id, $consumer_key)
{
$group_guid = 0;
$group = new ElggGroup($group_guid);
// Set the group properties that we can!
$group->name = $name;
$group->context_id = $context_id;
// This is a unique identifier from the consumer for this context
$group->consumer_key = $consumer_key;
// Which consumer is creating this group
$group->membership = ACCESS_PRIVATE;
$group->access_id = ACCESS_PUBLIC;
$group->briefdescription = elgg_echo('LTI:provision:group');
$consumer_instance = new LTI_Tool_Consumer_Instance($group->consumer_key, elgg_get_config('dbprefix'));
$context = new LTI_Context($consumer_instance, $group->context_id);
$group->description = $context->title;
$group->save();
$group->join($user);
// Add images
$prefix = 'groups/' . $group->guid;
$filename = GetImage($consumer_key, '.jpg');
$thumbtiny = get_resized_image_from_existing_file($filename, 25, 25, true);
$thumbsmall = get_resized_image_from_existing_file($filename, 40, 40, true);
$thumbmedium = get_resized_image_from_existing_file($filename, 100, 100, true);
$thumblarge = get_resized_image_from_existing_file($filename, 200, 200, false);
if ($thumbtiny) {
$thumb = new ElggFile();
$thumb->owner_guid = $group->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();
$group->icontime = time();
}
// return the URL
return $group;
}
示例3: zhsocial_apply_icon
function zhsocial_apply_icon($zh_user, $icon_url)
{
// if($zh_user->icontime)
// return;
$icon_sizes = elgg_get_config('icon_sizes');
$prefix = "profile/{$zh_user->guid}";
$filehandler = new ElggFile();
$filehandler->owner_guid = $zh_user->guid;
$filehandler->setFilename($prefix . ".jpg");
$filehandler->open("write");
$filehandler->write(file_get_contents($icon_url));
$filehandler->close();
$filename = $filehandler->getFilenameOnFilestore();
$sizes = array('topbar', 'tiny', 'small', 'medium', 'large', 'master');
$thumbs = array();
foreach ($sizes as $size) {
$thumbs[$size] = get_resized_image_from_existing_file($filename, $icon_sizes[$size]['w'], $icon_sizes[$size]['h'], $icon_sizes[$size]['square']);
}
if ($thumbs['tiny']) {
// just checking if resize successful
$thumb = new ElggFile();
$thumb->owner_guid = $zh_user->guid;
$thumb->setMimeType('image/jpeg');
foreach ($sizes as $size) {
$thumb->setFilename("{$prefix}{$size}.jpg");
$thumb->open("write");
$thumb->write($thumbs[$size]);
$thumb->close();
}
$zh_user->icontime = time();
}
}
示例4: pleiofile_generate_file_thumbs
function pleiofile_generate_file_thumbs(ElggObject $file)
{
if ($file->simpletype != "image") {
return null;
}
$file->icontime = time();
$sizes = array(60 => "thumb", 153 => "tinythumb", 153 => "smallthumb", 600 => "largethumb");
$filename = str_replace("file/", "", $file->getFilename());
foreach ($sizes as $size => $description) {
if ($size < 600) {
$upscale = true;
} else {
$upscale = false;
}
$thumbnail = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), $size, $size, $upscale);
if ($thumbnail) {
$path = "file/" . $description . "_" . $filename;
$thumb = new ElggFile();
$thumb->setMimeType($_FILES['upload']['type']);
$thumb->setFilename($path);
$thumb->open("write");
$thumb->write($thumbnail);
$thumb->close();
if ($description == "thumb") {
$file->thumbnail = $path;
} else {
$file->{$description} = $path;
}
unset($thumbnail);
}
}
}
示例5: saveSteps
/**
* Save the wiard steps to disk (because of DB limits)
*
* @param string[] $steps the wizard steps
*
* @return void
*/
public function saveSteps($steps)
{
if (!is_array($steps)) {
$steps = array($steps);
}
$fh = new ElggFile();
$fh->owner_guid = $this->getGUID();
$fh->setFilename('steps.json');
$fh->open('write');
$fh->write(json_encode($steps));
$fh->close();
}
示例6: uploadCK
function uploadCK($page, $identifier, $obj)
{
$funcNum2 = get_Input('CKEditorFuncNum', 'CKEditorFuncNum');
$file = new ElggFile();
$filestorename = strtolower(time() . $_FILES['upload']['name']);
$file->setFilename($filestorename);
$file->setMimeType($_FILES['upload']['type']);
$file->owner_guid = elgg_get_logged_in_user_guid();
$file->subtype = "file";
$file->originalfilename = $filestorename;
$file->access_id = ACCESS_PUBLIC;
$file->open("write");
$file->write(get_uploaded_file('upload'));
$file->close();
$result = $file->save();
if ($result) {
$master = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 550, 550);
if ($master !== false) {
$_SESSION['UPLOAD_DATA']['file_save'] = "started";
$filehandler = new ElggFile();
$filehandler->setFilename($filestorename);
$filehandler->setMimeType($_FILES['upload']['type']);
$filehandler->owner_guid = $user->guid;
$filehandler->subtype = "file";
$filehandler->originalfilename = $filestorename;
$filehandler->access_id = ACCESS_PUBLIC;
$filehandler->open("write");
$filehandler->write($master);
$filehandler->close();
$filehandler->save();
// Dev URL
$url = elgg_get_site_url() . 'CKEditorView?file_guid=' . $filehandler->guid;
//Production URL
//$url ='/CKEditorView?file_guid='.$filehandler->guid;
echo '<script type="text/javascript">
window.parent.CKEDITOR.tools.callFunction(' . $funcNum2 . ', "' . $url . '","");
</script>';
exit;
} else {
echo '<script type="text/javascript">
window.parent.CKEDITOR.tools.callFunction(' . $funcNum2 . ', "","");
</script>';
exit;
}
}
return true;
}
示例7: uploadIcon
public function uploadIcon($size, $contents)
{
$result = false;
if (in_array($size, $this->icon_sizes) && !empty($contents)) {
$this->username = $this->guid;
$icon = new ElggFile();
$icon->owner_guid = $this->guid;
$icon->setFilename("subsite_manager/" . $this->guid . "/subsite_icon/" . $size . ".jpg");
$icon->open("write");
$icon->write($contents);
$icon->close();
$this->icontime = time();
unset($this->username);
if ($this->save()) {
$result = true;
}
}
return $result;
}
示例8: videolist_2012022501
/**
* Downloads the thumbnail and saves into data folder
*
* @param ElggObject $item
* @return bool
*/
function videolist_2012022501($item)
{
// do not upgrade videos that have already been upgraded
if ($item->thumbnail === true) {
return true;
}
$thumbnail = file_get_contents($item->thumbnail);
if (!$thumbnail) {
return false;
}
$prefix = "videolist/" . $item->guid;
$filehandler = new ElggFile();
$filehandler->owner_guid = $item->owner_guid;
$filehandler->setFilename($prefix . ".jpg");
$filehandler->open("write");
$filehandler->write($thumbnail);
$filehandler->close();
$item->thumbnail = true;
return true;
}
示例9: testElggFileDelete
function testElggFileDelete()
{
global $CONFIG;
$user = $this->createTestUser();
$filestore = $this->filestore;
$dir = new \Elgg\EntityDirLocator($user->guid);
$file = new \ElggFile();
$file->owner_guid = $user->guid;
$file->setFilename('testing/ElggFileDelete');
$this->assertTrue($file->open('write'));
$this->assertTrue($file->write('Test'));
$this->assertTrue($file->close());
$file->save();
$filename = $file->getFilenameOnFilestore($file);
$filepath = $CONFIG->dataroot . $dir . "testing/ElggFileDelete";
$this->assertIdentical($filename, $filepath);
$this->assertTrue(file_exists($filepath));
$this->assertTrue($file->delete());
$this->assertFalse(file_exists($filepath));
$user->delete();
}
示例10: saveThumbnail
protected function saveThumbnail($image, $name)
{
try {
$thumbnail = get_resized_image_from_existing_file($image->getFilenameOnFilestore(), 60, 60, true);
} catch (Exception $e) {
return FALSE;
}
$thumb = new ElggFile();
$thumb->setMimeType('image/jpeg');
$thumb->access_id = $this->access_id;
$thumb->setFilename($name);
$thumb->open("write");
$thumb->write($thumbnail);
$thumb->save();
$image->thumbnail_guid = $thumb->getGUID();
if (!$thumb->getGUID()) {
$thumb->delete();
return FALSE;
}
return TRUE;
}
示例11: testFilenameOnFilestore
public function testFilenameOnFilestore()
{
global $CONFIG;
// create a user to own the file
$user = $this->createTestUser();
$created = date('Y/m/d', $user->time_created);
// setup a test file
$file = new ElggFile();
$file->owner_guid = $user->guid;
$file->setFilename('testing/filestore.txt');
$file->open('write');
$file->write('Testing!');
$this->assertTrue($file->close());
// ensure filename and path is expected
$filename = $file->getFilenameOnFilestore($file);
$filepath = "{$CONFIG->dataroot}{$created}/{$user->guid}/testing/filestore.txt";
$this->assertIdentical($filename, $filepath);
$this->assertTrue(file_exists($filepath));
// ensure file removed on user delete
$user->delete();
$this->assertFalse(file_exists($filepath));
}
开发者ID:ashwiniravi,项目名称:Elgg-Social-Network-Single-Sign-on-and-Web-Statistics,代码行数:22,代码来源:filestore.php
示例12: videolist_2012022501
/**
* Downloads the thumbnail and saves into data folder
*
* @param ElggObject $item
* @return bool
*/
function videolist_2012022501($item)
{
require_once elgg_get_plugins_path() . 'upgrade-tools/lib/upgrade_tools.php';
// get thumbnail image
$thumbnail = file_get_contents($item->thumbnail);
if (!$thumbnail) {
return false;
}
$prefix = "videolist/" . $item->guid;
$filehandler = new ElggFile();
$filehandler->owner_guid = $item->owner_guid;
$filehandler->setFilename($prefix . ".jpg");
$filehandler->open("write");
$filehandler->write($thumbnail);
$filehandler->close();
// update properties
if ($item->url) {
$item->video_url = $item->url;
$item->deleteMetadata('url');
}
if ($item->desc) {
$item->description = $item->desc;
$item->deleteMetadata('desc');
$item->save();
}
if ($item->embedurl) {
$item->deleteMetadata('embedurl');
}
upgrade_change_subtype($item, 'videolist_item');
// update river
$options = array('object_guid' => $item->guid);
$river_items = elgg_get_river($options);
foreach ($river_items as $river_item) {
if ($river_item->action_type == 'create') {
upgrade_update_river($river_item->id, 'river/object/videolist_item/create', $item->guid, 0);
}
}
return true;
}
示例13: haarlem_tangram_cache_xml
/**
* Cache the tangram vacancy xml
*
* @return void
*/
function haarlem_tangram_cache_xml()
{
$last_try = (int) haarlem_tangram_get_setting('tangram_last_update');
$tangram_url = haarlem_tangram_get_setting('tangram_url');
if (empty($tangram_url)) {
return;
}
if ($last_try > time() - 60 * 60) {
// prevent deadloop tries
return;
}
// store last try to prevent deadloops
elgg_set_plugin_setting('tangram_last_update', time(), 'haarlem_tangram');
// prepare cURL call
$ch = curl_init($tangram_url);
// settings
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// do the request
$content = curl_exec($ch);
$curl_info = curl_getinfo($ch);
// close curl
curl_close($ch);
// verify output
if (elgg_extract('http_code', $curl_info) !== 200 || stristr(elgg_extract('content_type', $curl_info), 'text/xml') === false) {
// something went wrong
return;
}
// save output
$plugin = elgg_get_plugin_from_id('haarlem_tangram');
$fh = new ElggFile();
$fh->owner_guid = $plugin->getGUID();
$fh->setFilename('tangram.xml');
$fh->open('write');
$fh->write($content);
$fh->close();
// set last success update
elgg_set_plugin_setting('tangram_last_update_success', time(), 'haarlem_tangram');
}
示例14: testDetectMimeType
function testDetectMimeType()
{
$user = $this->createTestUser();
$file = new \ElggFile();
$file->owner_guid = $user->guid;
$file->setFilename('testing/filestore.txt');
$file->open('write');
$file->write('Testing!');
$file->close();
$mime = $file->detectMimeType(null, 'text/plain');
// mime should not be null if default is set
$this->assertTrue(isset($mime));
// mime of a file object should match mime of a file path that represents this file on filestore
$resource_mime = $file->detectMimeType($file->getFilenameOnFilestore(), 'text/plain');
$this->assertIdentical($mime, $resource_mime);
// calling detectMimeType statically raises strict policy warning
// @todo: remove this once a new static method has been implemented
error_reporting(E_ALL & ~E_STRICT & ~E_DEPRECATED);
// method output should not differ between a static and a concrete call if the file path is set
$resource_mime_static = \ElggFile::detectMimeType($file->getFilenameOnFilestore(), 'text/plain');
$this->assertIdentical($resource_mime, $resource_mime_static);
error_reporting(E_ALL);
$user->delete();
}
示例15: socialink_linkedin_sync_profile_icon
/**
* Update the user profile with the LinkedIn profile image
*
* @param int $user_guid the user_guid to update
*
* @return bool
*/
function socialink_linkedin_sync_profile_icon($user_guid = 0)
{
$result = false;
if (empty($user_guid)) {
$user_guid = elgg_get_logged_in_user_guid();
}
if (($user = get_user($user_guid)) && socialink_linkedin_is_connected($user_guid)) {
if ($api_result = socialink_linkedin_get_profile_information($user_guid)) {
$api_result = json_decode($api_result);
if ($icon_url = $api_result->pictureUrl) {
if (file_get_contents($icon_url)) {
$icon_sizes = elgg_get_config("icon_sizes");
if (!empty($icon_sizes)) {
$fh = new ElggFile();
$fh->owner_guid = $user->getGUID();
foreach ($icon_sizes as $name => $properties) {
$resize = get_resized_image_from_existing_file($icon_url, $properties["w"], $properties["h"], $properties["square"], 0, 0, 0, 0, $properties["upscale"]);
if (!empty($resize)) {
$fh->setFilename("profile/" . $user->getGUID() . $name . ".jpg");
$fh->open("write");
$fh->write($resize);
$fh->close();
$result = true;
}
}
}
if (!empty($result)) {
$user->icontime = time();
// trigger event to let others know the icon was updated
elgg_trigger_event("profileiconupdate", $user->type, $user);
}
}
}
}
}
return $result;
}