当前位置: 首页>>代码示例>>PHP>>正文


PHP ElggFile::setMimeType方法代码示例

本文整理汇总了PHP中ElggFile::setMimeType方法的典型用法代码示例。如果您正苦于以下问题:PHP ElggFile::setMimeType方法的具体用法?PHP ElggFile::setMimeType怎么用?PHP ElggFile::setMimeType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ElggFile的用法示例。


在下文中一共展示了ElggFile::setMimeType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testCanSetMimeType

 /**
  * @group FileService
  */
 public function testCanSetMimeType()
 {
     unset($this->file->mimetype);
     $mimetype = 'application/plain';
     $this->file->setMimeType($mimetype);
     $this->assertEquals($mimetype, $this->file->getMimeType());
 }
开发者ID:elgg,项目名称:elgg,代码行数:10,代码来源:ElggFileTest.php

示例2: 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;
        }
    }
}
开发者ID:portokallidis,项目名称:Metamorphosis-Meducator,代码行数:30,代码来源:model.php

示例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();
    }
}
开发者ID:pingwangcs,项目名称:51zhaohu,代码行数:32,代码来源:start.php

示例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);
        }
    }
}
开发者ID:pleio,项目名称:pleiofile,代码行数:32,代码来源:functions.php

示例5: 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;
}
开发者ID:vsheokeen,项目名称:Elgg-Plugins,代码行数:50,代码来源:LTIGroup.php

示例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;
}
开发者ID:socialweb,项目名称:PiGo,代码行数:47,代码来源:start.php

示例7: 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;
 }
开发者ID:nohup,项目名称:community_plugins,代码行数:21,代码来源:PluginProject.php

示例8: identicon_check

/**
 * This makes sure that the image is present (builds it if it isn't) and then
 * displays it.
 */
function identicon_check($entity)
{
    //make sure the image functions are available before trying to make avatars
    if (function_exists("imagecreatetruecolor")) {
        // entity is group, user or something else?
        if ($entity instanceof ElggGroup) {
            $file = new ElggFile();
            $file->owner_guid = $entity->owner_guid;
            $seed = identicon_seed($entity);
            $file->setFilename('identicon/' . $seed . '/master.jpg');
            $file->setMimeType('image/jpeg');
            if (!$file->exists()) {
                if (identicon_build_group($seed, $file)) {
                    return true;
                } else {
                    // there was some error building the icon
                    return false;
                }
            } else {
                // file's already there
                return true;
            }
        } else {
            if ($entity instanceof ElggUser) {
                $file = new ElggFile();
                $file->owner_guid = $entity->getGUID();
                $seed = identicon_seed($entity);
                $file->setFilename('identicon/' . $seed . '/master.jpg');
                $file->setMimeType('image/jpeg');
                if (!$file->exists()) {
                    if (identicon_build($seed, $file)) {
                        return true;
                    } else {
                        // there was some error building the icon
                        return false;
                    }
                } else {
                    // file's already there
                    return true;
                }
            } else {
                // neither group nor user
                return false;
            }
        }
    }
    // we can't build the icon
    return false;
}
开发者ID:iionly,项目名称:identicon,代码行数:53,代码来源:start.php

示例9: elgg_file_viewer_convert_file

/**
 * Convert a video/audio file to a web compatible format
 * 
 * @param ElggFile $file   File entity
 * @param string   $format Format to convert to (extension)
 * @return ElggFile|false
 */
function elgg_file_viewer_convert_file($file, $format)
{
    if (!$file instanceof ElggFile || !$format) {
        return false;
    }
    $ffmpeg_path = elgg_get_plugin_setting('ffmpeg_path', 'elgg_file_viewer');
    if (!$ffmpeg_path) {
        return false;
    }
    $info = pathinfo($file->getFilenameOnFilestore());
    $filename = $info['filename'];
    $output = new ElggFile();
    $output->owner_guid = $file->owner_guid;
    $output->setFilename("projekktor/{$file->guid}/{$filename}.{$format}");
    $output->open('write');
    $output->close();
    try {
        $FFmpeg = new FFmpeg($ffmpeg_path);
        if (!$file->icontime) {
            $icon = new ElggFile();
            $icon->owner_guid = $file->owner_guid;
            $icon->setFilename("projekktor/{$file->guid}/{$filename}.jpg");
            $FFmpeg->input($file->getFilenameOnFilestore())->thumb(0, 1)->output($icon->getFilenameOnFilestore())->ready();
            if ($icon->exists()) {
                $file->icontime = time();
                $file->ffmpeg_thumb = $icon->getFilename();
                $prefix = 'file/';
                $filestorename = $file->icontime . $filename . '.jpg';
                $thumbnail = get_resized_image_from_existing_file($icon->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($icon->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($icon->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);
                }
            }
        }
        $FFmpeg->input($file->getFilenameOnFilestore())->output($output->getFilenameOnFilestore())->ready();
        elgg_log("Converting file {$file->guid} to {$format}: {$FFmpeg->command}", 'NOTICE');
    } catch (Exception $ex) {
        elgg_log($ex->getMessage(), 'ERROR');
        return false;
    }
    return $output;
}
开发者ID:hypejunction,项目名称:elgg_file_viewer,代码行数:74,代码来源:start.php

示例10: file_tools_unzip


//.........这里部分代码省略.........
            $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;
                    }
                }
                // 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') {
                    if ($filehandler->saveIconFromElggFile($filehandler)) {
                        $filehandler->thumbnail = $filehandler->getIcon('small')->getFilename();
                        $filehandler->smallthumb = $filehandler->getIcon('medium')->getFilename();
                        $filehandler->largethumb = $filehandler->getIcon('large')->getFilename();
                    }
                }
                set_input('folder_guid', $parent);
                $filehandler->save();
                $extracted = true;
                if (!empty($parent)) {
                    add_entity_relationship($parent, FILE_TOOLS_RELATIONSHIP, $filehandler->getGUID());
                }
            }
        }
        zip_entry_close($zip_entry);
    }
    zip_close($zip);
    return $extracted;
}
开发者ID:coldtrick,项目名称:file_tools,代码行数:101,代码来源:functions.php

示例11: saveImageFile

 /**
  * saves the image file
  * @param array $file_array
  *                      destination => path where to save the file
  *                      content => content of image
  *                      owner_id => owner id of the image file
  *
  * @return boolean
  */
 public static function saveImageFile($file_array)
 {
     if (!is_array($file_array)) {
         return FALSE;
     }
     $destination = $file_array['destination'];
     $content = $file_array['content'];
     $filehandler = new ElggFile();
     $filehandler->owner_guid = $file_array['owner_guid'] ? $file_array['owner_guid'] : elgg_get_logged_in_user_guid();
     $filehandler->setFilename($destination . '.jpg');
     $filehandler->open("write");
     $return = $filehandler->write($content);
     $filehandler->close();
     if ($file_array['create_thumbs'] && $return) {
         $thumbtopbar = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), 16, 16, true);
         $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 = $file_array['owner_guid'] ? $file_array['owner_guid'] : elgg_get_logged_in_user_guid();
             $thumb->setMimeType('image/jpeg');
             $thumb->setFilename($destination . 'topbar.jpg');
             $thumb->open("write");
             $thumb->write($thumbtopbar);
             $thumb->close();
             $thumb->setFilename($destination . 'tiny.jpg');
             $thumb->open("write");
             $thumb->write($thumbtiny);
             $thumb->close();
             $thumb->setFilename($destination . 'small.jpg');
             $thumb->open("write");
             $thumb->write($thumbsmall);
             $thumb->close();
             $thumb->setFilename($destination . 'medium.jpg');
             $thumb->open("write");
             $thumb->write($thumbmedium);
             $thumb->close();
             $thumb->setFilename($destination . 'large.jpg');
             $thumb->open("write");
             $thumb->write($thumblarge);
             $thumb->close();
         }
     }
     return $return;
 }
开发者ID:socialweb,项目名称:PiGo,代码行数:56,代码来源:IzapBase.php

示例12: market_add_image

/**
 * Add images to market post
 *
 * @param Market $post
 * @return array
 */
function market_add_image($post = NULL, $data = NULL, $imagenum = 0)
{
    if (!$post || !$data) {
        return false;
    }
    $filenum = $imagenum;
    if ($imagenum == 1) {
        $filenum = '';
    }
    $prefix = "market/" . $post->guid;
    $filehandler = new ElggFile();
    $filehandler->owner_guid = $post->owner_guid;
    $filehandler->setFilename($prefix . $filenum . ".jpg");
    $filehandler->open("write");
    $filehandler->write($data);
    $filehandler->close();
    $small = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), 40, 40, true);
    $medium = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), 153, 153, true);
    $large = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), 200, 200, false);
    $master = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), 600, 800, false);
    if ($small) {
        $sizes = array('small' => $small, 'medium' => $medium, 'large' => $large, 'master' => $master);
        foreach ($sizes as $size => $imgdata) {
            $thumb = new ElggFile();
            $thumb->owner_guid = $post->owner_guid;
            $thumb->setMimeType('image/jpeg');
            $thumb->setFilename($prefix . $size . $filenum . '.jpg');
            $thumb->open('write');
            $thumb->write($imgdata);
            $thumb->close();
        }
        // Set image in metadata array
        market_set_images($post, $imagenum);
    }
}
开发者ID:lorea,项目名称:Hydra-dev,代码行数:41,代码来源:market.php

示例13: ElggFile

$file->setMimeType($_FILES['upload']['type']);
$file->owner_guid = $user->guid;
$file->subtype = "file";
$file->originalfilename = $filestorename;
$file->access_id = ACCESS_DEFAULT;
$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_DEFAULT;
        $filehandler->open("write");
        $filehandler->write($master);
        $filehandler->close();
        $filehandler->save();
        $url = '' . $CONFIG->url . 'mod/CKEditor/image_viewer.php?file_guid=' . $filehandler->guid;
        echo '<script type="text/javascript">
		window.parent.CKEDITOR.tools.callFunction(' . $funcNum2 . ', "' . $url . '","Success");
		</script>';
        exit;
    } else {
        echo '<script type="text/javascript">
开发者ID:portokallidis,项目名称:Metamorphosis-Meducator,代码行数:31,代码来源:upload.php

示例14: createIconFile

 protected function createIconFile($size = 'small')
 {
     $file = new ElggFile();
     $sizes = elgg_get_config('icon_sizes');
     $tmp_name = tempnam("asd", "qerty");
     $contents = "";
     $success = false;
     if ($this->open("read")) {
         $contents = $this->read($this->getSize());
         if ($contents) {
             file_put_contents($tmp_name, $contents);
             $success = true;
         }
         $this->close();
     }
     if ($success == false) {
         register_error("cant read file");
         return null;
     }
     $imgsizearray = getimagesize($tmp_name);
     if ($imgsizearray == false) {
         register_error("bad file");
         return null;
     }
     $width = $imgsizearray[0];
     $height = $imgsizearray[1];
     $size_info = $sizes[$size];
     $file->setFilename(self::genGUID());
     $file->access_id = 2;
     $file->setMimeType($this->getMimeType());
     $file->save();
     $file->open("write");
     $file->write(self::cropImage($tmp_name, $width, $height, $size_info['w'], $size_info['h']));
     $file->close();
     unlink($tmp_name);
     return $file->guid;
 }
开发者ID:serega3000,项目名称:elgg_gallery_field,代码行数:37,代码来源:GalleryFieldImage.php

示例15: 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());
                            }
//.........这里部分代码省略.........
开发者ID:amcfarlane1251,项目名称:ongarde,代码行数:101,代码来源:functions_bu.php


注:本文中的ElggFile::setMimeType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。