本文整理汇总了PHP中ElggFile::detectMimeType方法的典型用法代码示例。如果您正苦于以下问题:PHP ElggFile::detectMimeType方法的具体用法?PHP ElggFile::detectMimeType怎么用?PHP ElggFile::detectMimeType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ElggFile
的用法示例。
在下文中一共展示了ElggFile::detectMimeType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCanDetectMimeType
/**
* @group FileService
*/
public function testCanDetectMimeType()
{
$mime = $this->file->detectMimeType(null, 'text/plain');
// mime should not be null if default is set
$this->assertNotNull($mime);
// mime of a file object should match mime of a file path that represents this file on filestore
$resource_mime = $this->file->detectMimeType($this->file->getFilenameOnFilestore(), 'text/plain');
$this->assertEquals($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($this->file->getFilenameOnFilestore(), 'text/plain');
$this->assertEquals($resource_mime, $resource_mime_static);
}
示例2: elgg_file_viewer_get_mime_type
/**
* Fix mime
*
* @param ElggFile $file File entity
* @return string
*/
function elgg_file_viewer_get_mime_type($file)
{
if (!$file instanceof ElggFile) {
return 'application/otcet-stream';
}
return $file->detectMimeType();
}
示例3: 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();
}
示例4: elgg_substr
}
// use same filename on the disk - ensures thumbnails are overwritten
$filestorename = $file->getFilename();
$filestorename = elgg_substr($filestorename, elgg_strlen($prefix));
} else {
$filestorename = elgg_strtolower(time() . $_FILES['upload']['name']);
}
$file->setFilename($prefix . $filestorename);
/*$indexOfExt = strrpos($_FILES['upload']['name'], ".") + 1;
$ext = substr($_FILES['upload']['name'],$indexOfExt);
error_log($ext);*/
$ext = pathinfo($_FILES['upload']['name'], PATHINFO_EXTENSION);
if ($ext == "ppt") {
$mime_type = 'application/vnd.ms-powerpoint';
} else {
$mime_type = ElggFile::detectMimeType($_FILES['upload']['tmp_name'], $_FILES['upload']['type'], $_FILES['upload']['name']);
}
// hack for Microsoft zipped formats
$info = pathinfo($_FILES['upload']['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;
示例5: projects_upload_attachments
/**
*
* upload attachments for a project
* @param ElggEntity
*
*/
function projects_upload_attachments($attachments, $project)
{
$count = count($attachments['name']);
for ($i = 0; $i < $count; $i++) {
if ($attachments['error'][$i] || !$attachments['name'][$i]) {
continue;
}
$name = $attachments['name'][$i];
$file = new ElggFile();
$file->container_guid = $project->guid;
$file->title = $name;
$file->access_id = (int) $project->access_id;
$prefix = "file/";
$filestorename = elgg_strtolower(time() . $name);
$file->setFilename($prefix . $filestorename);
$file->open("write");
$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";
}
//add_metastring("projectId");
//$file->projectId = $project_guid;
$file->setMimeType($mime_type);
$file->originalfilename = $name;
if (elgg_is_active_plugin('file')) {
$file->simpletype = file_get_simple_type($mime_type);
}
$saved = $file->save();
if ($saved) {
$file->addRelationship($project->guid, 'attachment');
}
}
}
}
示例6: 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)
{
$container_guid = (int) $container_guid;
$parent_guid = (int) $parent_guid;
if (empty($file) || empty($container_guid)) {
return false;
}
$container_entity = get_entity($container_guid);
if (empty($container_entity)) {
return false;
}
$extracted = false;
$allowed_extensions = file_tools_allowed_extensions();
$zipfile = elgg_extract('tmp_name', $file);
$access_id = get_input('access_id', false);
if ($access_id === false) {
$parent_folder = get_entity($parent_guid);
if (elgg_instanceof($parent_folder, 'object', FILE_TOOLS_SUBTYPE)) {
$access_id = $parent_folder->access_id;
} else {
if ($container_entity instanceof ElggGroup) {
$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);
$entity = file_tools_check_foldertitle_exists($folder, $container_guid, $parent);
if (!empty($entity)) {
$parent = $entity->getGUID();
} else {
if ($folder !== end($folder_array)) {
continue;
}
$prefix = 'file/';
$extension_array = explode('.', $folder);
$file_extension = end($extension_array);
if (!in_array(strtolower($file_extension), $allowed_extensions)) {
continue;
}
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
$filestorename = elgg_strtolower(time() . $folder);
// create the file
$filehandler = new ElggFile();
$filehandler->setFilename($prefix . $filestorename);
$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;
if (!$filehandler->save()) {
continue;
}
$filehandler->open('write');
$filehandler->write($buf);
$filehandler->close();
$mime_type = $filehandler->detectMimeType($filehandler->getFilenameOnFilestore());
// hack for Microsoft zipped formats
$info = pathinfo($folder);
$office_formats = ['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;
}
}
//.........这里部分代码省略.........
示例7: file_tools_get_mimetype
function file_tools_get_mimetype($tmp_file, $mime_type)
{
$mime_type = ElggFile::detectMimeType($tmp_file, $mime_type);
$info = pathinfo($tmp_file);
$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";
}
return $mime_type;
}
示例8: updateFile
public function updateFile($file, $params = array())
{
if (!$file->canEdit()) {
return true;
}
if ($params['title']) {
$file->title = $params['title'];
}
if (isset($params['access_id'])) {
$file->access_id = $params['access_id'];
}
if (isset($params['write_access_id'])) {
$file->write_access_id = $params['write_access_id'];
} else {
$file->write_access_id = ACCESS_PRIVATE;
}
if ($params['tags']) {
$file->tags = $params['tags'];
}
if ($params['stream']) {
$file->originalfilename = $params['filename'];
// Open the file to guarantee the directory exists
$file->open("write");
$file->close();
file_put_contents($file->getFilenameOnFilestore(), $params['stream']);
$mime_type = ElggFile::detectMimeType($file->getFilenameOnFilestore(), $params['type']);
$file->setMimeType($mime_type);
$file->simpletype = file_get_simple_type($mime_type);
pleiofile_generate_file_thumbs($file);
}
$result = $file->save();
if ($params['parent_guid'] != $file->parent_guid) {
$new_parent = get_entity($params['parent_guid']);
remove_entity_relationships($file->guid, "folder_of", true);
if ($new_parent instanceof ElggObject) {
add_entity_relationship($new_parent->guid, "folder_of", $file->guid);
}
}
return $result;
}
示例9: getIconFile
/**
* Returns an ElggFile containing the entity icon
*
* @param \ElggEntity $entity Entity
* @param string $size Size
* @return \ElggFile
*/
public function getIconFile(\ElggEntity $entity, $size = '')
{
$dir = $this->getIconDirectory($entity, $size);
$filename = $this->getIconFilename($entity, $size);
$file = new \ElggFile();
$file->owner_guid = $entity instanceof \ElggUser ? $entity->guid : $entity->owner_guid;
$file->setFilename("{$dir}/{$filename}");
if (!file_exists($file->getFilenameOnFilestore())) {
$file->open('write');
$file->close();
}
$file->mimetype = $file->detectMimeType();
return $file;
}
示例10: hj_inbox_send_message
/**
* Send a message to specified recipients
*
* @param int $sender_guid GUID of the sender entity
* @param array $recipient_guids An array of recipient GUIDs
* @param str $subject Subject of the message
* @param str $message Body of the message
* @param str $message_type Type of the message
* @param array $params Additional parameters, e.g. 'message_hash', 'attachments'
* @return boolean
*/
function hj_inbox_send_message($sender_guid, $recipient_guids, $subject = '', $message = '', $message_type = '', array $params = array())
{
$ia = elgg_set_ignore_access();
if (!is_array($recipient_guids)) {
$recipient_guids = array($recipient_guids);
}
if (isset($params['message_hash'])) {
$message_hash = elgg_extract('message_hash', $params);
}
if (isset($params['attachments'])) {
$attachments = elgg_extract('attachments', $params);
}
$user_guids = $recipient_guids;
$user_guids[] = $sender_guid;
sort($user_guids);
if (!$message_hash) {
$title = strtolower($subject);
$title = trim(str_replace('re:', '', $title));
$message_hash = sha1(implode(':', $user_guids) . $title);
}
$acl_hash = sha1(implode(':', $user_guids));
$dbprefix = elgg_get_config('dbprefix');
$query = "SELECT * FROM {$dbprefix}access_collections WHERE name = '{$acl_hash}'";
$collection = get_data_row($query);
//error_log(print_r($collection, true));
$acl_id = $collection->id;
if (!$acl_id) {
$site = elgg_get_site_entity();
$acl_id = create_access_collection($acl_hash, $site->guid);
update_access_collection($acl_id, $user_guids);
}
//error_log($acl_id);
$message_sent = new ElggObject();
$message_sent->subtype = "messages";
$message_sent->owner_guid = $sender_guid;
$message_sent->container_guid = $sender_guid;
$message_sent->access_id = ACCESS_PRIVATE;
$message_sent->title = $subject;
$message_sent->description = $message;
$message_sent->toId = $recipient_guids;
// the users receiving the message
$message_sent->fromId = $sender_guid;
// the user sending the message
$message_sent->readYet = 1;
// this is a toggle between 0 / 1 (1 = read)
$message_sent->hiddenFrom = 0;
// this is used when a user deletes a message in their sentbox, it is a flag
$message_sent->hiddenTo = 0;
// this is used when a user deletes a message in their inbox
$message_sent->msg = 1;
$message_sent->msgType = $message_type;
$message_sent->msgHash = $message_hash;
$message_sent->save();
if ($attachments) {
$count = count($attachments['name']);
for ($i = 0; $i < $count; $i++) {
if ($attachments['error'][$i] || !$attachments['name'][$i]) {
continue;
}
$name = $attachments['name'][$i];
$file = new ElggFile();
$file->container_guid = $message_sent->guid;
$file->title = $name;
$file->access_id = (int) $acl_id;
$prefix = "file/";
$filestorename = elgg_strtolower(time() . $name);
$file->setFilename($prefix . $filestorename);
$file->open("write");
$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
//.........这里部分代码省略.........
示例11: create
/**
* Create icons for an entity
*
* @param ElggEntity $entity Entity
* @param mixed $source ElggFile, or path, or temp storage to be used as a source for icons
* @param array $options Additional options
* 'icon_sizes' Additional icon sizes to create
* 'icon_filestore_prefix' Prefix of cropped/resizes icon sizes on the filestore
* 'coords' Cropping coords
* @return ElggFile[]|false Created icons
*/
public function create(ElggEntity $entity, $source = null, array $options = array())
{
if (!$entity instanceof ElggEntity) {
return false;
}
if (!$source) {
$source = $entity;
}
if ($source instanceof ElggFile) {
$source = $source->getFilenameOnFilestore();
}
if (empty($source) || !file_exists($source)) {
return false;
}
$coords = elgg_extract('coords', $options, false);
$dir = $this->getIconDirectory($entity, elgg_extract('icon_filestore_prefix', $options));
$entity->icon_mimetype = \ElggFile::detectMimeType($source, 'image/jpeg');
$entity->icon_directory = $dir;
// reset
unset($entity->icontime);
foreach (array('x1', 'x2', 'y1', 'y2') as $coord) {
unset($entity->{$coord});
}
$error = false;
$icons = array();
$icons_meta = array();
$icon_sizes = $this->getSizes($entity, elgg_extract('icon_sizes', $options, array()));
foreach ($icon_sizes as $size => $props) {
if (!isset($props['croppable'])) {
$props['croppable'] = in_array($size, $this->config->getCroppableSizes());
}
if (is_array($coords) && !isset($coords['master_width'])) {
$coords['master_width'] = $this->config->get('master_size_length');
$coords['master_height'] = $this->config->get('master_size_length');
}
try {
$icon = $this->getIconFile($entity, $size);
$image = new Image($source);
$image->resize($props, $coords);
$image->save($icon->getFilenameOnFilestore(), $this->config->getIconCompressionOpts());
$icons[$size] = $icon;
if (isset($props['metadata_name'])) {
$metadata_name = $props['metadata_name'];
$icons_meta[$metadata_name] = $icon->getFilename();
}
} catch (Exception $ex) {
elgg_log($ex->getMessage(), 'ERROR');
$error = true;
}
}
if ($error) {
foreach ($icons as $icon) {
$icon->delete();
}
return false;
}
if (!$entity instanceof ElggFile) {
// store the original icon source file
$src = $this->getIconFile($entity);
$srcimg = new Image($source);
$srcimg->save($src->getFilenameOnFilestore(), $this->config->getSrcCompressionOpts());
}
if (is_array($coords)) {
// store cropping coordinates
foreach ($coords as $coord => $value) {
$entity->{$coord} = $value;
}
}
foreach ($icons_meta as $name => $value) {
$entity->{$name} = $value;
}
$entity->icontime = time();
return $icons;
}
示例12: file_save_post
/**
* @param $title
* @param $description
* @param $username
* @param $access
* @param $tags
* @return array
* @throws InvalidParameterException
* @internal param $guid
* @internal param $size
*/
function file_save_post($title, $description, $username, $access, $tags)
{
$return = array();
if (!$username) {
$user = elgg_get_logged_in_user_entity();
} else {
$user = get_user_by_username($username);
if (!$user) {
throw new InvalidParameterException('registration:usernamenotvalid');
}
}
$loginUser = elgg_get_logged_in_user_entity();
$container_guid = $loginUser->guid;
if ($access == 'ACCESS_FRIENDS') {
$access_id = -2;
} elseif ($access == 'ACCESS_PRIVATE') {
$access_id = 0;
} elseif ($access == 'ACCESS_LOGGED_IN') {
$access_id = 1;
} elseif ($access == 'ACCESS_PUBLIC') {
$access_id = 2;
} else {
$access_id = -2;
}
$file = $_FILES["upload"];
if (empty($file)) {
$response['status'] = 1;
$response['result'] = elgg_echo("file:blank");
return $response;
}
$new_file = true;
if ($new_file) {
$file = new ElggFile();
$file->subtype = "file";
// if no title on new upload, grab filename
if (empty($title)) {
$title = htmlspecialchars($_FILES['upload']['name'], ENT_QUOTES, 'UTF-8');
}
}
$file->title = $title;
$file->description = $description;
$file->access_id = $access_id;
$file->container_guid = $container_guid;
$file->tags = string_to_tag_array($tags);
// we have a file upload, so process it
if (isset($_FILES['upload']['name']) && !empty($_FILES['upload']['name'])) {
$prefix = "file/";
$filestorename = elgg_strtolower(time() . $_FILES['upload']['name']);
$file->setFilename($prefix . $filestorename);
$file->originalfilename = $_FILES['upload']['name'];
$mime_type = $file->detectMimeType($_FILES['upload']['tmp_name'], $_FILES['upload']['type']);
$file->setMimeType($mime_type);
$file->simpletype = elgg_get_file_simple_type($mime_type);
// Open the file to guarantee the directory exists
$file->open("write");
$file->close();
move_uploaded_file($_FILES['upload']['tmp_name'], $file->getFilenameOnFilestore());
$fileSaved = $file->save();
// if image, we need to create thumbnails (this should be moved into a function)
if ($fileSaved && $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($_FILES['upload']['type']);
$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);
//.........这里部分代码省略.........
示例13: hj_framework_process_file_upload
/**
* Process uploaded files
*
* @param mixed $files Uploaded files
* @param mixed $entity If an entity is set and it doesn't belong to one of the file subtypes, uploaded files will be converted into hjFile objects and attached to the entity
* @return void
*/
function hj_framework_process_file_upload($name, $entity = null)
{
// Normalize the $_FILES array
if (is_array($_FILES[$name]['name'])) {
$files = hj_framework_prepare_files_global($_FILES);
$files = $files[$name];
} else {
$files = $_FILES[$name];
$files = array($files);
}
if (elgg_instanceof($entity)) {
if (!$entity instanceof hjFile) {
$is_attachment = true;
}
$subtype = $entity->getSubtype();
}
foreach ($files as $file) {
if (!is_array($file) || $file['error']) {
continue;
}
if ($is_attachment) {
$filehandler = new hjFile();
} else {
$filehandler = new hjFile($entity->guid);
}
$prefix = 'hjfile/';
if ($entity instanceof hjFile) {
$filename = $filehandler->getFilenameOnFilestore();
if (file_exists($filename)) {
unlink($filename);
}
$filestorename = $filehandler->getFilename();
$filestorename = elgg_substr($filestorename, elgg_strlen($prefix));
} else {
$filestorename = elgg_strtolower(time() . $file['name']);
}
$filehandler->setFilename($prefix . $filestorename);
$filehandler->title = $file['name'];
$mime_type = ElggFile::detectMimeType($file['tmp_name'], $file['type']);
// hack for Microsoft zipped formats
$info = pathinfo($file['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";
}
$filehandler->setMimeType($mime_type);
$filehandler->originalfilename = $file['name'];
$filehandler->simpletype = hj_framework_get_simple_type($mime_type);
$filehandler->filesize = $file['size'];
$filehandler->open("write");
$filehandler->close();
move_uploaded_file($file['tmp_name'], $filehandler->getFilenameOnFilestore());
if ($filehandler->save()) {
if ($is_attachment && elgg_instanceof($entity)) {
make_attachment($entity->guid, $filehandler->getGUID());
}
// Generate icons for images
if ($filehandler->simpletype == "image") {
if (!elgg_instanceof($entity) || $is_attachment) {
// no entity provided or this is an attachment generating icons for self
hj_framework_generate_entity_icons($filehandler, $filehandler);
} else {
if (elgg_instanceof($entity)) {
hj_framework_generate_entity_icons($entity, $filehandler);
}
}
// the settings tell us not to keep the original image file, so downsizing to master
if (!HYPEFRAMEWORK_FILES_KEEP_ORIGINALS) {
$icon_sizes = hj_framework_get_thumb_sizes($subtype);
$values = $icon_sizes['master'];
$master = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), $values['w'], $values['h'], $values['square'], 0, 0, 0, 0, $values['upscale']);
$filehandler->open('write');
$filehandler->write($master);
$filehandler->close();
}
}
$return[$file['name']] = $filehandler->getGUID();
} else {
$return[$file['name']] = false;
//.........这里部分代码省略.........
示例14: getIconFile
/**
* Returns an ElggFile containing the entity icon
*
* @param \ElggEntity $entity Entity
* @param string $size Size
* @return \ElggFile
*/
public function getIconFile(\ElggEntity $entity, $size = '')
{
$dir = $this->getIconDirectory($entity, $size);
$filename = $this->getIconFilename($entity, $size);
if ($entity instanceof \ElggUser) {
$owner_guid = $entity->guid;
} else {
if ($entity->owner_guid) {
$owner_guid = $entity->owner_guid;
} else {
$owner_guid = elgg_get_site_entity();
}
}
$file = new \ElggFile();
$file->owner_guid = $owner_guid;
$file->setFilename("{$dir}/{$filename}");
$file->mimetype = $file->detectMimeType();
return $file;
}
示例15: createFile
public function createFile($path = array(), $filename = "", $filestream = false, $access_id = 0)
{
if (!isset($filename)) {
if (count($path) < 1) {
throw new Exception('Path length must be at least one.');
}
if (count($path) == 1) {
$parent = $this->container;
} else {
$parent_guid = array_slice($path, -2)[0];
$parent = get_entity($parent_guid);
}
$filename = array_slice($path, -1)[0];
} else {
if (count($path) == 0) {
$parent = $this->container;
} else {
$parent_guid = array_slice($path, -1)[0];
$parent = get_entity($parent_guid);
}
}
if (!$parent | !$parent->canWriteToContainer()) {
return false;
}
if (!$access_id) {
if ($parent instanceof ElggObject) {
// lower level folder
$access_id = $parent->access_id;
} elseif ($parent instanceof ElggGroup) {
// top level folder
$access_id = $parent->group_acl;
} else {
throw new Exception('Invalid container.');
}
}
$file = new FilePluginFile();
$file->subtype = "file";
$file->title = $filename;
$file->access_id = $access_id;
$file->container_guid = $this->container->guid;
$filestorename = elgg_strtolower(time() . $filename);
$file->setFilename("file/" . $filestorename);
$file->originalfilename = $filename;
if ($filestream) {
file_put_contents($file->getFilenameOnFilestore(), $filestream);
} else {
$input = fopen("php://input", "r");
file_put_contents($file->getFilenameOnFilestore(), $input);
}
$mime_type = ElggFile::detectMimeType($file->getFilenameOnFilestore(), mime_content_type($filename));
$file->setMimeType($mime_type);
$file->simpletype = file_get_simple_type($mime_type);
$file->save();
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($_FILES['upload']['type']);
$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);
}
}
if ($parent != $this->container && $parent instanceof ElggObject) {
add_entity_relationship($parent->guid, FILE_TOOLS_RELATIONSHIP, $file->guid);
}
}