本文整理汇总了PHP中ElggFile::getGUID方法的典型用法代码示例。如果您正苦于以下问题:PHP ElggFile::getGUID方法的具体用法?PHP ElggFile::getGUID怎么用?PHP ElggFile::getGUID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ElggFile
的用法示例。
在下文中一共展示了ElggFile::getGUID方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setFolderGUID
/**
* Set the folder for the file
*
* @param \ElggFile $entity the file to edit
*
* @return void
*/
protected static function setFolderGUID(\ElggFile $entity)
{
$folder_guid = get_input('folder_guid', false);
if ($folder_guid === false) {
// folder_input was not present in form/action
// maybe someone else did something with a file
return;
}
$folder_guid = (int) $folder_guid;
if (!empty($folder_guid)) {
$folder = get_entity($folder_guid);
if (!elgg_instanceof($folder, 'object', FILE_TOOLS_SUBTYPE)) {
unset($folder_guid);
}
}
// remove old relationships
remove_entity_relationships($entity->getGUID(), FILE_TOOLS_RELATIONSHIP, true);
if (!empty($folder_guid)) {
add_entity_relationship($folder_guid, FILE_TOOLS_RELATIONSHIP, $entity->getGUID());
}
}
示例2: 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;
}
示例3: profile_manager_profileupdate_user_event
function profile_manager_profileupdate_user_event($event, $object_type, $user)
{
if (!empty($user) && $user instanceof ElggUser) {
// upload a file to your profile
$accesslevel = get_input('accesslevel');
if (!is_array($accesslevel)) {
$accesslevel = array();
}
$options = array("type" => "object", "subtype" => CUSTOM_PROFILE_FIELDS_PROFILE_SUBTYPE, "limit" => false, "metadata_name_value_pairs" => array("name" => "metadata_type", "value" => "pm_file"));
if ($configured_fields = elgg_get_entities_from_metadata($options)) {
foreach ($configured_fields as $field) {
// check for uploaded files
$metadata_name = $field->metadata_name;
$current_file_guid = $user->{$metadata_name};
if (isset($accesslevel[$metadata_name])) {
$access_id = (int) $accesslevel[$metadata_name];
} else {
// this should never be executed since the access level should always be set
$access_id = ACCESS_PRIVATE;
}
if (isset($_FILES[$metadata_name]) && $_FILES[$metadata_name]['error'] == 0) {
// uploaded file exists so, save it to an ElggFile object
// use current_file_guid to overwrite previously uploaded files
$filehandler = new ElggFile($current_file_guid);
$filehandler->owner_guid = $user->getGUID();
$filehandler->container_guid = $user->getGUID();
$filehandler->subtype = "file";
$filehandler->access_id = $access_id;
$filehandler->title = $field->getTitle();
$filehandler->setFilename("profile_manager/" . $_FILES[$metadata_name]["name"]);
$filehandler->setMimeType($_FILES[$metadata_name]["type"]);
$filehandler->open("write");
$filehandler->write(get_uploaded_file($metadata_name));
$filehandler->close();
if ($filehandler->save()) {
$filehandler->profile_manager_metadata_name = $metadata_name;
// used to retrieve user file when deleting
$filehandler->originalfilename = $_FILES[$metadata_name]["name"];
create_metadata($user->guid, $metadata_name, $filehandler->getGUID(), 'text', $user->guid, $access_id);
}
} else {
// if file not uploaded should it be deleted???
if (empty($current_file_guid)) {
// find the previously uploaded file and if exists... delete it
$options = array("type" => "object", "subtype" => "file", "owner_guid" => $user->getGUID(), "limit" => 1, "metadata_name_value_pairs" => array("name" => "profile_manager_metadata_name", "value" => $metadata_name));
if ($files = elgg_get_entities_from_metadata($options)) {
$file = $files[0];
$file->delete();
}
} else {
if ($file = get_entity($current_file_guid)) {
// maybe we need to update the access id
$file->access_id = $access_id;
$file->save();
}
}
}
}
}
// update profile completeness
profile_manager_profile_completeness($user);
}
}
示例4: file_tools_unzip
/**
* Unzip an uploaded zip file
*
* @param array $file the $_FILES information
* @param int $container_guid the container to put the files/folders under
* @param int $parent_guid the parrent folder
*
* @return bool
*/
function file_tools_unzip($file, $container_guid, $parent_guid = 0)
{
$extracted = false;
if (!empty($file) && !empty($container_guid)) {
$allowed_extensions = file_tools_allowed_extensions();
$zipfile = elgg_extract("tmp_name", $file);
$container_entity = get_entity($container_guid);
$access_id = get_input("access_id", false);
if ($access_id === false) {
if (!empty($parent_guid) && ($parent_folder = get_entity($parent_guid)) && elgg_instanceof($parent_folder, "object", FILE_TOOLS_SUBTYPE)) {
$access_id = $parent_folder->access_id;
} else {
if (elgg_instanceof($container_entity, "group")) {
$access_id = $container_entity->group_acl;
} else {
$access_id = get_default_access($container_entity);
}
}
}
// open the zip file
$zip = zip_open($zipfile);
while ($zip_entry = zip_read($zip)) {
// open the zip entry
zip_entry_open($zip, $zip_entry);
// set some variables
$zip_entry_name = zip_entry_name($zip_entry);
$filename = basename($zip_entry_name);
// check for folder structure
if (strlen($zip_entry_name) != strlen($filename)) {
// there is a folder structure, check it and create missing items
file_tools_create_folders($zip_entry, $container_guid, $parent_guid);
}
// extract the folder structure from the zip entry
$folder_array = explode("/", $zip_entry_name);
$parent = $parent_guid;
foreach ($folder_array as $folder) {
$folder = utf8_encode($folder);
if ($entity = file_tools_check_foldertitle_exists($folder, $container_guid, $parent)) {
$parent = $entity->getGUID();
} else {
if ($folder == end($folder_array)) {
$prefix = "file/";
$extension_array = explode('.', $folder);
$file_extension = end($extension_array);
if (in_array(strtolower($file_extension), $allowed_extensions)) {
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
// create the file
$filehandler = new ElggFile();
$filehandler->setFilename($prefix . $folder);
$filehandler->title = $folder;
$filehandler->originalfilename = $folder;
$filehandler->owner_guid = elgg_get_logged_in_user_guid();
$filehandler->container_guid = $container_guid;
$filehandler->access_id = $access_id;
$filehandler->open("write");
$filehandler->write($buf);
$filehandler->close();
$mime_type = $filehandler->detectMimeType($filehandler->getFilenameOnFilestore());
// hack for Microsoft zipped formats
$info = pathinfo($folder);
$office_formats = array("docx", "xlsx", "pptx");
if ($mime_type == "application/zip" && in_array($info["extension"], $office_formats)) {
switch ($info["extension"]) {
case "docx":
$mime_type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
break;
case "xlsx":
$mime_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
break;
case "pptx":
$mime_type = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
break;
}
}
// check for bad ppt detection
if ($mime_type == "application/vnd.ms-office" && $info["extension"] == "ppt") {
$mime_type = "application/vnd.ms-powerpoint";
}
$simple_type = file_get_simple_type($mime_type);
$filehandler->setMimeType($mime_type);
$filehandler->simpletype = $simple_type;
if ($simple_type == "image") {
$filestorename = elgg_strtolower(time() . $folder);
$thumb = new ElggFile();
$thumb->owner_guid = elgg_get_logged_in_user_guid();
$thumbnail = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), 60, 60, true);
if ($thumbnail) {
$thumb->setFilename($prefix . "thumb" . $filestorename);
$thumb->open("write");
$thumb->write($thumbnail);
$thumb->close();
//.........这里部分代码省略.........
示例5: file_tools_unzip
function file_tools_unzip($file, $container_guid, $parent_guid = 0)
{
$extracted = false;
if (!empty($file) && !empty($container_guid)) {
$allowed_extensions = file_tools_allowed_extensions();
$zipfile = elgg_extract("tmp_name", $file);
$container_entity = get_entity($container_guid);
$access_id = get_input("access_id", false);
if ($access_id === false) {
if (!empty($parent_guid) && ($parent_folder = get_entity($parent_guid)) && elgg_instanceof($parent_folder, "object", FILE_TOOLS_SUBTYPE)) {
$access_id = $parent_folder->access_id;
} else {
if (elgg_instanceof($container_entity, "group")) {
$access_id = $container_entity->group_acl;
} else {
$access_id = get_default_access($container_entity);
}
}
}
// open the zip file
$zip = zip_open($zipfile);
while ($zip_entry = zip_read($zip)) {
// open the zip entry
zip_entry_open($zip, $zip_entry);
// set some variables
$zip_entry_name = zip_entry_name($zip_entry);
$filename = basename($zip_entry_name);
// check for folder structure
if (strlen($zip_entry_name) != strlen($filename)) {
// there is a folder structure, check it and create missing items
file_tools_create_folders($zip_entry, $container_guid, $parent_guid);
}
// extract the folder structure from the zip entry
$folder_array = explode("/", $zip_entry_name);
$parent = $parent_guid;
foreach ($folder_array as $folder) {
$folder = sanitize_string(utf8_encode($folder));
if ($entity = file_tools_check_foldertitle_exists($folder, $container_guid, $parent)) {
$parent = $entity->getGUID();
} else {
if ($folder == end($folder_array)) {
$prefix = "file/";
$extension_array = explode('.', $folder);
$file_extension = end($extension_array);
$file_size = zip_entry_filesize($zip_entry);
if (in_array(strtolower($file_extension), $allowed_extensions)) {
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
// create the file
$filehandler = new ElggFile();
$filehandler->setFilename($prefix . $folder);
$filehandler->title = $folder;
$filehandler->originalfilename = $folder;
$filehandler->owner_guid = elgg_get_logged_in_user_guid();
$filehandler->container_guid = $container_guid;
$filehandler->access_id = $access_id;
$filehandler->open("write");
$filehandler->write($buf);
$filehandler->close();
$mime_type = mime_content_type($filehandler->getFilenameOnFilestore());
$simple_type = explode("/", $mime_type);
$filehandler->setMimeType($mime_type);
$filehandler->simpletype = $simple_type[0];
if ($simple_type[0] == "image") {
$filestorename = elgg_strtolower(time() . $folder);
$thumbnail = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), 60, 60, true);
if ($thumbnail) {
$thumb = new ElggFile();
$thumb->setMimeType($mime_type);
$thumb->setFilename($prefix . "thumb" . $filestorename);
$thumb->open("write");
$thumb->write($thumbnail);
$thumb->close();
$filehandler->thumbnail = $prefix . "thumb" . $filestorename;
unset($thumbnail);
}
$thumbsmall = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), 153, 153, true);
if ($thumbsmall) {
$thumb->setFilename($prefix . "smallthumb" . $filestorename);
$thumb->open("write");
$thumb->write($thumbsmall);
$thumb->close();
$filehandler->smallthumb = $prefix . "smallthumb" . $filestorename;
unset($thumbsmall);
}
$thumblarge = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), 600, 600, false);
if ($thumblarge) {
$thumb->setFilename($prefix . "largethumb" . $filestorename);
$thumb->open("write");
$thumb->write($thumblarge);
$thumb->close();
$filehandler->largethumb = $prefix . "largethumb" . $filestorename;
unset($thumblarge);
}
}
set_input('folder_guid', $parent);
$filehandler->save();
$extracted = true;
if (!empty($parent)) {
add_entity_relationship($parent, FILE_TOOLS_RELATIONSHIP, $filehandler->getGUID());
}
//.........这里部分代码省略.........
示例6: hj_inbox_send_message
//.........这里部分代码省略.........
$file->close();
move_uploaded_file($attachments['tmp_name'][$i], $file->getFilenameOnFilestore());
$saved = $file->save();
if ($saved) {
$mime_type = ElggFile::detectMimeType($attachments['tmp_name'][$i], $attachments['type'][$i]);
$info = pathinfo($name);
$office_formats = array('docx', 'xlsx', 'pptx');
if ($mime_type == "application/zip" && in_array($info['extension'], $office_formats)) {
switch ($info['extension']) {
case 'docx':
$mime_type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
break;
case 'xlsx':
$mime_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
break;
case 'pptx':
$mime_type = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
break;
}
}
// check for bad ppt detection
if ($mime_type == "application/vnd.ms-office" && $info['extension'] == "ppt") {
$mime_type = "application/vnd.ms-powerpoint";
}
$file->msgHash = $message_hash;
$file->toId = $recipient_guids;
$file->fromId = $sender_guid;
$file->setMimeType($mime_type);
$file->originalfilename = $name;
if (elgg_is_active_plugin('file')) {
$file->simpletype = file_get_simple_type($mime_type);
}
$file->save();
$guid = $file->getGUID();
$uploaded_attachments[] = $guid;
$attachment_urls .= '<div class="inbox-attachment">' . elgg_view('output/url', array('href' => "messages/download/{$guid}", 'text' => $file->title, 'is_trusted' => true)) . '</div>';
if ($file->simpletype == "image") {
$file->icontime = time();
$thumbnail = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 60, 60, true);
if ($thumbnail) {
$thumb = new ElggFile();
$thumb->setMimeType($attachments['type'][$i]);
$thumb->setFilename($prefix . "thumb" . $filestorename);
$thumb->open("write");
$thumb->write($thumbnail);
$thumb->close();
$file->thumbnail = $prefix . "thumb" . $filestorename;
unset($thumbnail);
}
$thumbsmall = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 153, 153, true);
if ($thumbsmall) {
$thumb->setFilename($prefix . "smallthumb" . $filestorename);
$thumb->open("write");
$thumb->write($thumbsmall);
$thumb->close();
$file->smallthumb = $prefix . "smallthumb" . $filestorename;
unset($thumbsmall);
}
$thumblarge = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 600, 600, false);
if ($thumblarge) {
$thumb->setFilename($prefix . "largethumb" . $filestorename);
$thumb->open("write");
$thumb->write($thumblarge);
$thumb->close();
$file->largethumb = $prefix . "largethumb" . $filestorename;
unset($thumblarge);