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


PHP ElggFile::save方法代码示例

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


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

示例1: save

 /**
  * Save the podcast
  *
  * @param array $data File data to upload, if null then we're just setting attribute
  * @return bool
  *
  * @throws InvalidPodcastFileException|IOException
  */
 public function save($data = NULL)
 {
     if (!parent::save()) {
         return FALSE;
     }
     // New Podcast File Data
     if ($data) {
         $this->simpletype = "audio";
         // Get mimetype
         $mime_type = ElggPodcast::detectMimeType($data['tmp_name'], $data['type']);
         // Check for valid mime type
         if (ElggPodcast::checkValidMimeType($mime_type)) {
             // Set it
             $this->setMimeType($mime_type);
         } else {
             // Invalid, fail
             $ex = elgg_echo('InvalidPodcastFileException:InvalidMimeType', array($mime_type));
             throw new InvalidPodcastFileException($ex);
         }
         // Remove old file if it exists
         $old_file = $this->getFilenameOnFilestore();
         if (file_exists($old_file) && !is_dir($old_file)) {
             unlink($old_file);
         }
         // Save the file data
         $this->savePodcastFile($data);
         // Populate metadata
         $this->populatePodcastMetadata();
     }
     return TRUE;
 }
开发者ID:amcfarlane1251,项目名称:ongarde,代码行数:39,代码来源:ElggPodcast.php

示例2: save

 /**
  * Save the image
  *
  * @warning container_guid must be set first
  *
  * @param array $data
  * @return bool
  */
 public function save($data = null)
 {
     if (!parent::save()) {
         return false;
     }
     if ($data) {
         // new image
         $this->simpletype = "image";
         $this->saveImageFile($data);
         $this->saveThumbnails();
     }
     return true;
 }
开发者ID:rijojoy,项目名称:MyIceBerg,代码行数:21,代码来源:TidypicsImage.php

示例3: 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

示例4: 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();
 }
开发者ID:epsylon,项目名称:Hydra-dev,代码行数:21,代码来源:ElggCoreFilestoreTest.php

示例5: 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

示例6: pleio_api_save_file

function pleio_api_save_file($data = "", $file_name = "", $title = "", $description = "", $tags = "", $file_id = null, $folder_id = 0, $group_id = 0, $access_id = "", $wiki_id = "", $mimetype = "")
{
    $file_id = $file_id ? $file_id : null;
    $user = elgg_get_logged_in_user_entity();
    $user_id = $user !== false ? $user->guid : 0;
    if (!$data && !$file_id) {
        return new ErrorResult(elgg_echo("file:uploadfailed"));
    }
    $swordfish_group = $group_id ? pleio_api_swordfish_group($group_id) : false;
    if ($swordfish_group) {
        $group = get_entity($group_id);
        $url = pleio_api_swordfish_baseurl($group->site_guid) . "post-file";
        $swordfish_name = pleio_api_swordfish_username($user->username);
        $params = array("data" => $data, "title" => $title);
        if ($file_id) {
            $params["fileId"] = $file_id;
        } elseif ($folder_id) {
            $params["folderId"] = $folder_id;
        } elseif ($group_id) {
            $params["groupId"] = $swordfish_group;
        } else {
            return new ErrorResult("Vul minimaal een bestand, folder of groep in");
        }
        if ($wiki_id) {
            $params["wikiId"] = $wiki_id;
        }
        if ($access_id != ACCESS_PRIVATE) {
            $params["visibility"] = "internally_published";
        } else {
            $params["visibility"] = "private";
        }
        $params["filename"] = $file_name;
        $result = pleio_api_call_swordfish_api($swordfish_name, $url, "POST", $params);
        if ($result->ok) {
            if (strpos($result->headers["CONTENT-TYPE"], "json")) {
                $response = json_decode($result->response);
                return new SaveSuccessResult(elgg_echo("file:saved"), $response->id);
            } else {
                return new ErrorResult($result->headers["BOBO-EXCEPTION-VALUE"]);
            }
        } else {
            return new ErrorResult($result->headers["BOBO-EXCEPTION-VALUE"]);
        }
    } else {
        if ($file_id) {
            $file = get_entity($file_id);
        }
        if (!$file) {
            $file = new ElggFile();
            $file->owner_guid = $user_id;
        }
        if ($title) {
            $file->title = $title;
        }
        if ($description) {
            $file->setDescription($description);
        }
        if ($tags) {
            $file->setMetaData("tags", $tags);
        }
        if ($group_id) {
            $file->setContainerGUID($group_id);
        }
        if ($access_id) {
            $file->access_id = $access_id;
        }
        if ($data) {
            $file->setFilename(basename($file_name));
            $data = base64_decode($data);
            $fh = $file->open("write");
            if ($fh) {
                $file->write($data);
                $file->close();
            }
            if (!$mimetype) {
                $mimetype = $file->detectMimeType($file->getFilenameOnFilestore());
            }
            $file->setMimeType($mimetype);
            $file->simpletype = file_get_simple_type($mimetype);
        }
        if (!$file->save()) {
            return new ErrorResult(elgg_echo("file:uploadfailed"));
        }
        if ($folder_id) {
            remove_entity_relationships($file->guid, "folder_of", 1);
            add_entity_relationship($folder_id, "folder_of", $file->guid);
        }
        if (!$file_id) {
            add_to_river('river/object/file/create', 'create', $user_id, $file->guid);
        }
        return new SaveSuccessResult(elgg_echo("file:saved"), $file->guid);
    }
    return new ErrorResult(elgg_echo("file:uploadfailed"));
}
开发者ID:appstaat,项目名称:pleio_api,代码行数:94,代码来源:methods.php

示例7: createFromFile

 /**
  * 
  * @param string $tmp_name path to file
  * @param string $type mime type
  * @return self
  * @throws Exception
  */
 public static function createFromFile($tmp_name, $type)
 {
     $mime_type = ElggFile::detectMimeType($tmp_name, $type);
     if (false == in_array($mime_type, array("image/jpeg", "image/jpg"))) {
         register_error(elgg_echo("gallery_field:only_jpg"));
         return null;
     }
     $ext = "jpg";
     $file = new self();
     $thumb_file = new ElggFile();
     $random_guid = self::genGUID();
     $file->setFilename($random_guid . "." . $ext);
     $thumb_file->setFilename($random_guid . "_thumb." . $ext);
     $file->setMimeType($mime_type);
     $thumb_file->setMimeType($mime_type);
     $imgsizearray = getimagesize($tmp_name);
     if ($imgsizearray == false) {
         register_error("bad file");
         return null;
     }
     $width = $imgsizearray[0];
     $height = $imgsizearray[1];
     $file->open("write");
     $file->write(self::cropImage($tmp_name, $width, $height, 760, 580));
     $file->close();
     $thumb_file->open("write");
     $thumb_file->write(self::cropImage($tmp_name, $width, $height, 200, 140));
     $thumb_file->close();
     $thumb_file->save();
     $file->thumb_file_guid = $thumb_file->guid;
     $file->save();
     return $file;
 }
开发者ID:epsylon,项目名称:Hydra-dev,代码行数:40,代码来源:GalleryFieldImage.php

示例8: deleteAlbumDir

 /**
  * Delete the album directory on disk
  */
 protected function deleteAlbumDir()
 {
     $tmpfile = new ElggFile();
     $tmpfile->setFilename('image/' . $this->guid . '/._tmp_del_tidypics_album_');
     $tmpfile->subtype = 'image';
     $tmpfile->owner_guid = $this->owner_guid;
     $tmpfile->container_guid = $this->guid;
     $tmpfile->open("write");
     $tmpfile->write('');
     $tmpfile->close();
     $tmpfile->save();
     $albumdir = eregi_replace('/._tmp_del_tidypics_album_', '', $tmpfile->getFilenameOnFilestore());
     $tmpfile->delete();
     if (is_dir($albumdir)) {
         rmdir($albumdir);
     }
 }
开发者ID:rijojoy,项目名称:MyIceBerg,代码行数:20,代码来源:TidypicsAlbum.php

示例9: 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);
    }
}
开发者ID:remy40,项目名称:gvrs,代码行数:63,代码来源:events.php

示例10: file_tools_unzip


//.........这里部分代码省略.........
                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();
                                    $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);
                                }
                                unset($thumb);
                            }
                            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:lorea,项目名称:Hydra-dev,代码行数:101,代码来源:functions.php

示例11: time

 $file_url = $faker->imageURL();
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, $file_url);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
 $file_contents = curl_exec($ch);
 $curl_info = curl_getinfo($ch);
 curl_close($ch);
 $mime_type = $curl_info['content_type'];
 $file->setMimeType($mime_type);
 $file->simpletype = file_get_simple_type($mime_type);
 $file->open('write');
 $file->write($file_contents);
 $file->close();
 if ($file->save()) {
     $success++;
     if (substr_count($mime_type, 'image/')) {
         $file->icontime = time();
         $prefix = "files/";
         $thumbnail = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 60, 60, true);
         if ($thumbnail) {
             $thumb = new ElggFile();
             $thumb->owner_guid = $file->owner_guid;
             $thumb->setFilename($prefix . "thumb" . $file->originalfilename);
             $thumb->open("write");
             $thumb->write($thumbnail);
             $thumb->close();
             $file->thumbnail = $prefix . "thumb" . $file->originalfilename;
             unset($thumbnail);
         }
开发者ID:hypejunction,项目名称:hypefaker,代码行数:31,代码来源:gen_files.php

示例12: ElggFile

//get all time released files
$content = elgg_get_entities_from_access_id(array('type' => 'object', 'subtype' => 'file', 'access_id' => 0, 'limit' => 5000, 'joins' => $joins, 'wheres' => $wheres));
foreach ($content as $file) {
    $releaseFlag = false;
    if ($file->releaseDate < date("Y-m-d")) {
        $releaseFlag = true;
    }
    if ($file->releaseDate == date("Y-m-d")) {
        if ($file->releaseTime <= date('H:i', time())) {
            $releaseFlag = true;
        }
    }
    if ($releaseFlag === true) {
        $fileObj = new ElggFile($file->guid);
        $fileObj->access_id = $fileObj->releasedAccessId;
        if ($fileObj->save()) {
            elgg_delete_metadata(array('guid' => $file->guid, 'metadata_name' => 'isTimeReleased'));
            elgg_delete_metadata(array('guid' => $file->guid, 'metadata_name' => 'releaseDate'));
            elgg_delete_metadata(array('guid' => $file->guid, 'metadata_name' => 'releaseTime'));
            elgg_delete_metadata(array('guid' => $file->guid, 'metadata_name' => 'releasedAccessId'));
        } else {
        }
    }
}
$wheres = array("msv.string = 'isClosable'");
//get all files ready to be closed / deleted
$content = elgg_get_entities(array('type' => 'object', 'subtype' => 'file', 'limit' => 5000, 'joins' => $joins, 'wheres' => $wheres));
foreach ($content as $file) {
    $deleteFlag = false;
    if ($file->closeDate == date("Y-m-d")) {
        if ($file->closeTime <= date('H:i', time())) {
开发者ID:amcfarlane1251,项目名称:ongarde,代码行数:31,代码来源:releaser.php

示例13: 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);
//.........这里部分代码省略.........
开发者ID:manlui,项目名称:elgg_with_rest_api,代码行数:101,代码来源:file.php

示例14: 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;
                    }
                }
//.........这里部分代码省略.........
开发者ID:coldtrick,项目名称:file_tools,代码行数:101,代码来源:functions.php

示例15: fopen

 // get the file from flickr and save it locally
 $filename = $file->getFilenameOnFilestore();
 $destination = fopen($filename, "w");
 $source = fopen($photo["url"], "r");
 while ($a = fread($source, 1024)) {
     fwrite($destination, $a);
 }
 fclose($source);
 fclose($destination);
 /*
 $file->open("write");
 $file->write();
 $file->write(get_uploaded_file($key));
 $file->close();
 */
 $result = $file->save();
 if (!$result) {
     array_push($not_uploaded, $sent_file['name']);
     array_push($error_msgs, elgg_echo('tidypics:save_error'));
     continue;
 }
 //add tags
 create_metadata($file->guid, "tags", $photo["tags"], "text", $user->guid, ACCESS_PUBLIC);
 //add title and description
 create_object_entity($file->guid, $photo["title"], $photo["description"]);
 //get and store the exif data
 td_get_exif($file);
 // resize photos to create thumbnails
 if ($image_lib == 'ImageMagick') {
     // ImageMagick command line
     if (tp_create_im_cmdline_thumbnails($file, $prefix, $filestorename) != true) {
开发者ID:rijojoy,项目名称:MyIceBerg,代码行数:31,代码来源:flickrImportPhotoset1.php


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