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


PHP Db::free_result方法代码示例

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


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

示例1: call

 public static function call()
 {
     $langpref = isset($_GET['langpref']) ? $_GET['langpref'] : Settings::get('SITELANG');
     $langprefs = explode("|", $langpref);
     # Determine which user is logged in to OC.
     require_once $GLOBALS['rootpath'] . "okapi/lib/oc_session.php";
     $OC_user_id = OCSession::get_user_id();
     if ($OC_user_id == null) {
         $after_login = "okapi/apps/" . ($langpref != Settings::get('SITELANG') ? "?langpref=" . $langpref : "");
         $login_url = Settings::get('SITE_URL') . "login.php?target=" . urlencode($after_login);
         return new OkapiRedirectResponse($login_url);
     }
     # Get the list of authorized apps.
     $rs = Db::query("\n            select c.`key`, c.name, c.url\n            from\n                okapi_consumers c,\n                okapi_authorizations a\n            where\n                a.user_id = '" . Db::escape_string($OC_user_id) . "'\n                and c.`key` = a.consumer_key\n            order by c.name\n        ");
     $vars = array();
     $vars['okapi_base_url'] = Settings::get('SITE_URL') . "okapi/";
     $vars['site_url'] = Settings::get('SITE_URL');
     $vars['site_name'] = Okapi::get_normalized_site_name();
     $vars['site_logo'] = Settings::get('SITE_LOGO');
     $vars['apps'] = array();
     while ($row = Db::fetch_assoc($rs)) {
         $vars['apps'][] = $row;
     }
     Db::free_result($rs);
     $response = new OkapiHttpResponse();
     $response->content_type = "text/html; charset=utf-8";
     ob_start();
     Okapi::gettext_domain_init($langprefs);
     include 'index.tpl.php';
     $response->body = ob_get_clean();
     Okapi::gettext_domain_restore();
     return $response;
 }
开发者ID:kratenko,项目名称:oc-server3,代码行数:33,代码来源:index.php

示例2: ParamMissing

 function validate_image_uuid($request)
 {
     $image_uuid = $request->get_parameter('image_uuid');
     if (!$image_uuid) {
         throw new ParamMissing('image_uuid');
     }
     # When uploading images, OCPL stores the user_id of the uploader
     # in the 'pictures' table. This is redundant to cache_logs.user_id,
     # because only the log entry author may append images. We will stick
     # to log_entries.user_id here, which is the original value and works
     # for all OC branches, and ignore pictures.user_id.
     $rs = Db::query("\n            select\n                cache_logs.id log_internal_id,\n                cache_logs.user_id,\n                pictures.node\n            from cache_logs\n            join pictures on pictures.object_id = cache_logs.id\n            where pictures.object_type = 1 and pictures.uuid = '" . Db::escape_string($image_uuid) . "'\n        ");
     $row = Db::fetch_assoc($rs);
     Db::free_result($rs);
     if (!$row) {
         throw new InvalidParam('image_uuid', "There is no log entry image with uuid '" . $image_uuid . "'.");
     }
     if ($row['node'] != Settings::get('OC_NODE_ID')) {
         throw new Exception("This site's database contains the image '{$image_uuid}' which has been" . " imported from another OC node. OKAPI is not prepared for that.");
     }
     if ($row['user_id'] != $request->token->user_id) {
         throw new InvalidParam('image_uuid', "The user of your access token is not the author of the associated log entry.");
     }
     return array($image_uuid, $row['log_internal_id']);
 }
开发者ID:kratenko,项目名称:oc-server3,代码行数:25,代码来源:log_images_common.inc.php

示例3: call

 public static function call(OkapiRequest $request)
 {
     $usernames = $request->get_parameter('usernames');
     if (!$usernames) {
         throw new ParamMissing('usernames');
     }
     $usernames = explode("|", $usernames);
     if (count($usernames) > 500) {
         throw new InvalidParam('usernames', "Maximum allowed number of referenced users " . "is 500. You provided " . count($usernames) . " usernames.");
     }
     $fields = $request->get_parameter('fields');
     if (!$fields) {
         throw new ParamMissing('fields');
     }
     # There's no need to validate the fields parameter as the 'users'
     # method does this (it will raise a proper exception on invalid values).
     $rs = Db::query("\n            select username, uuid\n            from user\n            where username collate " . Settings::get('DB_CHARSET') . "_general_ci in ('" . implode("','", array_map('\\okapi\\Db::escape_string', $usernames)) . "')\n        ");
     $lower_username2useruuid = array();
     while ($row = Db::fetch_assoc($rs)) {
         $lower_username2useruuid[mb_strtolower($row['username'], 'utf-8')] = $row['uuid'];
     }
     Db::free_result($rs);
     # Retrieve data for the found user_uuids.
     if (count($lower_username2useruuid) > 0) {
         $id_results = OkapiServiceRunner::call('services/users/users', new OkapiInternalRequest($request->consumer, $request->token, array('user_uuids' => implode("|", array_values($lower_username2useruuid)), 'fields' => $fields)));
     } else {
         $id_results = array();
     }
     # Map user_uuids back to usernames. Also check which usernames were not found
     # and mark them with null.
     $results = array();
     foreach ($usernames as $username) {
         if (!isset($lower_username2useruuid[mb_strtolower($username, 'utf-8')])) {
             $results[$username] = null;
         } else {
             $results[$username] = $id_results[$lower_username2useruuid[mb_strtolower($username, 'utf-8')]];
         }
     }
     return Okapi::formatted_response($request, $results);
 }
开发者ID:kratenko,项目名称:oc-server3,代码行数:40,代码来源:by_usernames.php

示例4: call

 public static function call(OkapiRequest $request)
 {
     $internal_ids = $request->get_parameter('internal_ids');
     if (!$internal_ids) {
         throw new ParamMissing('internal_ids');
     }
     $internal_ids = explode("|", $internal_ids);
     if (count($internal_ids) > 500) {
         throw new InvalidParam('internal_ids', "Maximum allowed number of referenced users " . "is 500. You provided " . count($internal_ids) . " references.");
     }
     $fields = $request->get_parameter('fields');
     if (!$fields) {
         throw new ParamMissing('fields');
     }
     # There's no need to validate the fields parameter as the 'users'
     # method does this (it will raise a proper exception on invalid values).
     $rs = Db::query("\n            select user_id, uuid\n            from user\n            where user_id in ('" . implode("','", array_map('\\okapi\\Db::escape_string', $internal_ids)) . "')\n        ");
     $internalid2useruuid = array();
     while ($row = Db::fetch_assoc($rs)) {
         $internalid2useruuid[$row['user_id']] = $row['uuid'];
     }
     Db::free_result($rs);
     # Retrieve data on given user_uuids.
     $id_results = OkapiServiceRunner::call('services/users/users', new OkapiInternalRequest($request->consumer, $request->token, array('user_uuids' => implode("|", array_values($internalid2useruuid)), 'fields' => $fields)));
     # Map user_uuids to internal_ids. Also check which internal_ids were not found
     # and mark them with null.
     $results = array();
     foreach ($internal_ids as $internal_id) {
         if (!isset($internalid2useruuid[$internal_id])) {
             $results[$internal_id] = null;
         } else {
             $results[$internal_id] = $id_results[$internalid2useruuid[$internal_id]];
         }
     }
     return Okapi::formatted_response($request, $results);
 }
开发者ID:kratenko,项目名称:oc-server3,代码行数:36,代码来源:by_internal_ids.php

示例5: call

 public static function call(OkapiRequest $request)
 {
     $user_uuids = $request->get_parameter('user_uuids');
     if (!$user_uuids) {
         throw new ParamMissing('user_uuids');
     }
     $user_uuids = explode("|", $user_uuids);
     if (count($user_uuids) > 500) {
         throw new InvalidParam('user_uuids', "Maximum allowed number of referenced users " . "is 500. You provided " . count($user_uuids) . " user IDs.");
     }
     $fields = $request->get_parameter('fields');
     if (!$fields) {
         throw new ParamMissing('fields');
     }
     $fields = explode("|", $fields);
     foreach ($fields as $field) {
         if (!in_array($field, self::$valid_field_names)) {
             throw new InvalidParam('fields', "'{$field}' is not a valid field code.");
         }
     }
     $rs = Db::query("\n            select user_id, uuid, username, admin, latitude, longitude, date_created\n            from user\n            where uuid in ('" . implode("','", array_map('\\okapi\\Db::escape_string', $user_uuids)) . "')\n        ");
     $results = array();
     $id2uuid = array();
     $uuid2id = array();
     while ($row = Db::fetch_assoc($rs)) {
         $id2uuid[$row['user_id']] = $row['uuid'];
         $uuid2id[$row['uuid']] = $row['user_id'];
         $entry = array();
         foreach ($fields as $field) {
             switch ($field) {
                 case 'uuid':
                     $entry['uuid'] = $row['uuid'];
                     break;
                 case 'username':
                     $entry['username'] = $row['username'];
                     break;
                 case 'profile_url':
                     $entry['profile_url'] = Settings::get('SITE_URL') . "viewprofile.php?userid=" . $row['user_id'];
                     break;
                 case 'is_admin':
                     if (!$request->token) {
                         $entry['is_admin'] = null;
                     } elseif ($request->token->user_id != $row['user_id']) {
                         $entry['is_admin'] = null;
                     } else {
                         $entry['is_admin'] = $row['admin'] ? true : false;
                     }
                     break;
                 case 'internal_id':
                     $entry['internal_id'] = $row['user_id'];
                     break;
                 case 'date_registered':
                     $entry['date_registered'] = date("Y-m-d", strtotime($row['date_created']));
                 case 'caches_found':
                     /* handled separately */
                     break;
                 case 'caches_notfound':
                     /* handled separately */
                     break;
                 case 'caches_hidden':
                     /* handled separately */
                     break;
                 case 'rcmds_given':
                     /* handled separately */
                     break;
                 case 'home_location':
                     if (!$request->token) {
                         $entry['home_location'] = null;
                     } elseif ($request->token->user_id != $row['user_id']) {
                         $entry['home_location'] = null;
                     } elseif (!$row['latitude'] && !$row['longitude']) {
                         # OCPL sets NULL/NULL for unknown location, OCDE sets 0/0.
                         # It is safe to return null also for OCPL 0/0, as this value
                         # does not make sense.
                         $entry['home_location'] = null;
                     } else {
                         $entry['home_location'] = round($row['latitude'], 6) . "|" . round($row['longitude'], 6);
                     }
                     break;
                 default:
                     throw new Exception("Missing field case: " . $field);
             }
         }
         $results[$row['uuid']] = $entry;
     }
     Db::free_result($rs);
     # caches_found, caches_notfound, caches_hidden
     if (in_array('caches_found', $fields) || in_array('caches_notfound', $fields) || in_array('caches_hidden', $fields) || in_array('rcmds_given', $fields)) {
         # We will load all these stats together. Then we may remove these which
         # the user doesn't need.
         $extras = array();
         if (Settings::get('OC_BRANCH') == 'oc.pl') {
             # OCPL stores user stats in 'user' table.
             $rs = Db::query("\n                    select user_id, founds_count, notfounds_count, hidden_count\n                    from user\n                    where user_id in ('" . implode("','", array_map('\\okapi\\Db::escape_string', array_keys($id2uuid))) . "')\n                ");
         } else {
             # OCDE stores user stats in 'stat_user' table.
             $rs = Db::query("\n                    select\n                        u.user_id,\n                        ifnull(su.found, 0) as founds_count,\n                        ifnull(su.notfound, 0) as notfounds_count,\n                        ifnull(su.hidden, 0) as hidden_count\n                    from\n                        user u\n                        left join stat_user su\n                            on su.user_id = u.user_id\n                    where u.user_id in ('" . implode("','", array_map('\\okapi\\Db::escape_string', array_keys($id2uuid))) . "')\n                ");
         }
         while ($row = Db::fetch_assoc($rs)) {
             $extras[$row['user_id']] = array();
//.........这里部分代码省略.........
开发者ID:kratenko,项目名称:oc-server3,代码行数:101,代码来源:users.php

示例6: call


//.........这里部分代码省略.........
                 case 'state':
                     /* handled separately */
                     break;
                 case 'last_found':
                     $entry['last_found'] = $row['last_found'] > '1980' ? date('c', strtotime($row['last_found'])) : null;
                     break;
                 case 'last_modified':
                     $entry['last_modified'] = date('c', strtotime($row['last_modified']));
                     break;
                 case 'date_created':
                     $entry['date_created'] = date('c', strtotime($row['date_created']));
                     break;
                 case 'date_hidden':
                     $entry['date_hidden'] = date('c', strtotime($row['date_hidden']));
                     break;
                 case 'internal_id':
                     $entry['internal_id'] = $row['cache_id'];
                     break;
                 case 'attribution_note':
                     /* handled separately */
                     break;
                 case 'protection_areas':
                     /* handled separately */
                     break;
                 default:
                     throw new Exception("Missing field case: " . $field);
             }
         }
         $results[$row['wp_oc']] = $entry;
         if ($row['listing_outdated'] > 0) {
             $outdated_listings[] = $row['wp_oc'];
         }
     }
     Db::free_result($rs);
     # owner
     if (in_array('owner', $fields) && count($results) > 0) {
         $rs = Db::query("\n                select user_id, uuid, username\n                from user\n                where user_id in ('" . implode("','", array_map('\\okapi\\Db::escape_string', array_values($owner_ids))) . "')\n            ");
         $tmp = array();
         while ($row = Db::fetch_assoc($rs)) {
             $tmp[$row['user_id']] = $row;
         }
         foreach ($results as $cache_code => &$result_ref) {
             $row = $tmp[$owner_ids[$cache_code]];
             $result_ref['owner'] = array('uuid' => $row['uuid'], 'username' => $row['username'], 'profile_url' => Settings::get('SITE_URL') . "viewprofile.php?userid=" . $row['user_id']);
         }
     }
     # is_found
     if (in_array('is_found', $fields)) {
         if ($user_id == null) {
             throw new BadRequest("Either 'user_uuid' parameter OR Level 3 Authentication is required to access 'is_found' field.");
         }
         $tmp = Db::select_column("\n                select c.wp_oc\n                from\n                    caches c,\n                    cache_logs cl\n                where\n                    c.cache_id = cl.cache_id\n                    and cl.type in (\n                        '" . Db::escape_string(Okapi::logtypename2id("Found it")) . "',\n                        '" . Db::escape_string(Okapi::logtypename2id("Attended")) . "'\n                    )\n                    and cl.user_id = '" . Db::escape_string($user_id) . "'\n                    " . (Settings::get('OC_BRANCH') == 'oc.pl' ? "and cl.deleted = 0" : "") . "\n            ");
         $tmp2 = array();
         foreach ($tmp as $cache_code) {
             $tmp2[$cache_code] = true;
         }
         foreach ($results as $cache_code => &$result_ref) {
             $result_ref['is_found'] = isset($tmp2[$cache_code]);
         }
     }
     # is_not_found
     if (in_array('is_not_found', $fields)) {
         if ($user_id == null) {
             throw new BadRequest("Either 'user_uuid' parameter OR Level 3 Authentication is required to access 'is_not_found' field.");
         }
         $tmp = Db::select_column("\n                select c.wp_oc\n                from\n                    caches c,\n                    cache_logs cl\n                where\n                    c.cache_id = cl.cache_id\n                    and cl.type = '" . Db::escape_string(Okapi::logtypename2id("Didn't find it")) . "'\n                    and cl.user_id = '" . Db::escape_string($user_id) . "'\n                    " . (Settings::get('OC_BRANCH') == 'oc.pl' ? "and cl.deleted = 0" : "") . "\n            ");
开发者ID:kratenko,项目名称:oc-server3,代码行数:67,代码来源:geocaches.php

示例7: call

 public static function call(OkapiRequest $request)
 {
     $log_uuids = $request->get_parameter('log_uuids');
     if ($log_uuids === null) {
         throw new ParamMissing('log_uuids');
     }
     if ($log_uuids === "") {
         $log_uuids = array();
     } else {
         $log_uuids = explode("|", $log_uuids);
     }
     if (count($log_uuids) > 500 && !$request->skip_limits) {
         throw new InvalidParam('log_uuids', "Maximum allowed number of referenced " . "log entries is 500. You provided " . count($log_uuids) . " UUIDs.");
     }
     if (count($log_uuids) != count(array_unique($log_uuids))) {
         throw new InvalidParam('log_uuids', "Duplicate UUIDs detected (make sure each UUID is referenced only once).");
     }
     $fields = $request->get_parameter('fields');
     if (!$fields) {
         $fields = "date|user|type|comment";
     }
     $fields = explode("|", $fields);
     foreach ($fields as $field) {
         if (!in_array($field, self::$valid_field_names)) {
             throw new InvalidParam('fields', "'{$field}' is not a valid field code.");
         }
     }
     if (Settings::get('OC_BRANCH') == 'oc.de') {
         $teamentry_field = 'cl.oc_team_comment';
         $ratingdate_condition = 'and cr.rating_date=cl.date';
         $needs_maintenance_SQL = 'cl.needs_maintenance';
         $listing_is_outdated_SQL = 'cl.listing_outdated';
     } else {
         $teamentry_field = '(cl.type=12)';
         $ratingdate_condition = '';
         $needs_maintenance_SQL = 'IF(cl.type=5, 2, IF(cl.type=6, 1, 0))';
         $listing_is_outdated_SQL = '0';
     }
     $rs = Db::query("\n            select\n                cl.id, c.wp_oc as cache_code, cl.uuid, cl.type,\n                " . $teamentry_field . " as oc_team_entry,\n                " . $needs_maintenance_SQL . " as needs_maintenance2,\n                " . $listing_is_outdated_SQL . " as listing_is_outdated,\n                unix_timestamp(cl.date) as date, cl.text,\n                u.uuid as user_uuid, u.username, u.user_id,\n                if(cr.user_id is null, 0, 1) as was_recommended\n            from\n                (cache_logs cl,\n                user u,\n                caches c)\n                left join cache_rating cr\n                    on cr.user_id = u.user_id\n                    and cr.cache_id = c.cache_id\n                    " . $ratingdate_condition . "\n                    and cl.type in (\n                        " . Okapi::logtypename2id("Found it") . ",\n                        " . Okapi::logtypename2id("Attended") . "\n                    )\n            where\n                cl.uuid in ('" . implode("','", array_map('\\okapi\\Db::escape_string', $log_uuids)) . "')\n                and " . (Settings::get('OC_BRANCH') == 'oc.pl' ? "cl.deleted = 0" : "true") . "\n                and cl.user_id = u.user_id\n                and c.cache_id = cl.cache_id\n                and c.status in (1,2,3)\n        ");
     $results = array();
     $log_id2uuid = array();
     /* Maps logs' internal_ids to uuids */
     $flag_options = array('null', 'false', 'true');
     while ($row = Db::fetch_assoc($rs)) {
         $results[$row['uuid']] = array('uuid' => $row['uuid'], 'cache_code' => $row['cache_code'], 'date' => date('c', $row['date']), 'user' => array('uuid' => $row['user_uuid'], 'username' => $row['username'], 'profile_url' => Settings::get('SITE_URL') . "viewprofile.php?userid=" . $row['user_id']), 'type' => Okapi::logtypeid2name($row['type']), 'was_recommended' => $row['was_recommended'] ? true : false, 'needs_maintenance2' => $flag_options[$row['needs_maintenance2']], 'listing_is_outdated' => $flag_options[$row['listing_is_outdated']], 'oc_team_entry' => $row['oc_team_entry'] ? true : false, 'comment' => Okapi::fix_oc_html($row['text'], Okapi::OBJECT_TYPE_CACHE_LOG), 'images' => array(), 'internal_id' => $row['id']);
         $log_id2uuid[$row['id']] = $row['uuid'];
     }
     Db::free_result($rs);
     # fetch images
     if (in_array('images', $fields)) {
         # For OCPL log entry images, pictures.seq currently is always = 1,
         # while OCDE uses it for ordering the images.
         $rs = Db::query("\n                select object_id, uuid, url, title, spoiler\n                from pictures\n                where\n                    object_type = 1\n                    and object_id in ('" . implode("','", array_map('\\okapi\\Db::escape_string', array_keys($log_id2uuid))) . "')\n                    and display = 1   /* currently is always 1 for logpix */\n                    and unknown_format = 0\n                order by seq, date_created\n            ");
         if (Settings::get('OC_BRANCH') == 'oc.de') {
             $object_type_param = 'type=1&';
         } else {
             $object_type_param = '';
         }
         while ($row = Db::fetch_assoc($rs)) {
             $results[$log_id2uuid[$row['object_id']]]['images'][] = array('uuid' => $row['uuid'], 'url' => $row['url'], 'thumb_url' => Settings::get('SITE_URL') . 'thumbs.php?' . $object_type_param . 'uuid=' . $row['uuid'], 'caption' => $row['title'], 'is_spoiler' => $row['spoiler'] ? true : false);
         }
         Db::free_result($rs);
     }
     # Check which UUIDs were not found and mark them with null.
     foreach ($log_uuids as $log_uuid) {
         if (!isset($results[$log_uuid])) {
             $results[$log_uuid] = null;
         }
     }
     # Remove unwanted fields.
     foreach (self::$valid_field_names as $field) {
         if (!in_array($field, $fields)) {
             foreach ($results as &$result_ref) {
                 unset($result_ref[$field]);
             }
         }
     }
     # Order the results in the same order as the input codes were given.
     $ordered_results = array();
     foreach ($log_uuids as $log_uuid) {
         $ordered_results[$log_uuid] = $results[$log_uuid];
     }
     return Okapi::formatted_response($request, $ordered_results);
 }
开发者ID:kratenko,项目名称:oc-server3,代码行数:84,代码来源:entries.php

示例8: select_column

 /** Fetch all [(A), (B), (C)], return [A, B, C]. */
 public static function select_column($query)
 {
     $column = array();
     $rs = self::query($query);
     while (true) {
         $values = Db::fetch_row($rs);
         if ($values === false) {
             break;
         }
         array_push($column, $values[0]);
     }
     Db::free_result($rs);
     return $column;
 }
开发者ID:kojoty,项目名称:opencaching-pl,代码行数:15,代码来源:core.php

示例9: _call

 /**
  * Append a new image to a log entry and return the image uuid and position.
  * Throws CannotPublishException or BadRequest on errors.
  */
 private static function _call(OkapiRequest $request)
 {
     require_once 'log_images_common.inc.php';
     # Developers! Please notice the fundamental difference between throwing
     # CannotPublishException and the "standard" BadRequest/InvalidParam
     # exceptions. You're reading the "_call" method now (see below for
     # "call").
     # validate the 'log_uuid' parameter
     $log_uuid = $request->get_parameter('log_uuid');
     if (!$log_uuid) {
         throw new ParamMissing('log_uuid');
     }
     $rs = Db::query("\n            select id, node, user_id\n            from cache_logs\n            where uuid = '" . Db::escape_string($log_uuid) . "'");
     $row = Db::fetch_assoc($rs);
     Db::free_result($rs);
     if (!$row) {
         throw new InvalidParam('log_uuid', "There is no log entry with uuid '" . $log_uuid . "'.");
     }
     if ($row['node'] != Settings::get('OC_NODE_ID')) {
         throw new Exception("This site's database contains the log entry '{$log_uuid}' which has been" . " imported from another OC node. OKAPI is not prepared for that.");
     }
     if ($row['user_id'] != $request->token->user_id) {
         throw new InvalidParam('log_uuid', "The user of your access token is not the log entry's author.");
     }
     $log_internal_id = $row['id'];
     unset($row);
     # validate the 'caption', 'is_spoiler' and 'position' parameters
     $caption = $request->get_parameter('caption');
     if (!$caption) {
         throw new CannotPublishException(sprintf(_("Please enter an image caption."), Okapi::get_normalized_site_name()));
     }
     $is_spoiler = $request->get_parameter('is_spoiler');
     if ($is_spoiler === null) {
         $is_spoiler = 'false';
     }
     if (!in_array($is_spoiler, array('true', 'false'))) {
         throw new InvalidParam('is_spoiler');
     }
     $position = LogImagesCommon::validate_position($request);
     # validate the 'image' parameter
     $base64_image = $request->get_parameter('image');
     if (!$base64_image) {
         throw new ParamMissing('image');
     }
     $estimated_decoded_size = strlen($base64_image) / 4 * 3 - 2;
     if ($estimated_decoded_size > Settings::get('IMAGE_MAX_UPLOAD_SIZE')) {
         $estimated_decoded_size_MB = round($estimated_decoded_size / 1024 / 1024, 1);
         $max_upload_size_MB = round(Settings::get('IMAGE_MAX_UPLOAD_SIZE') / 1024 / 1024, 1);
         throw new CannotPublishException(sprintf(_("Your image file is too large (%s.%s MB); %s accepts a maximum image size of %s.%s MB."), floor($estimated_decoded_size_MB), $estimated_decoded_size_MB * 10 % 10, Okapi::get_normalized_site_name(), floor($max_upload_size_MB), $max_upload_size_MB * 10 % 10));
     }
     $image = base64_decode($base64_image);
     if (!$image) {
         throw new InvalidParam('image', "bad base64 encoding");
     }
     try {
         $image_properties = getimagesizefromstring($image);
         # can throw
         if (!$image_properties) {
             throw new Exception();
         }
         list($width, $height, $image_type) = $image_properties;
         if (!in_array($image_type, array(IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_GIF))) {
             # This will happen e.g. for BMP and XBM images, which are supported by GD.
             throw new Exception();
         }
     } catch (Exception $e) {
         # Note: There may be *subtypes* which are not accepted by the GD library.
         # About 1 of 2000 JPEGs at OC.de is not readable by the PHP functions,
         # though they can be displayed by web browsers.
         throw new CannotPublishException(sprintf(_("The uploaded image file is broken, or the image type is not accepted by %s. Allowed types are JPEG, PNG and GIF."), Okapi::get_normalized_site_name()));
     }
     unset($image_properties);
     if ($width * $height > self::max_pixels($base64_image)) {
         # This large image may crash the image processing functions.
         throw new CannotPublishException(sprintf(_("The uploaded image is too large (%s megapixels), please downscale it."), round($width * $height / 1024 / 1024)));
     }
     try {
         $image = imagecreatefromstring($image);
         # can throw
         if (!$image) {
             throw new Exception();
         }
     } catch (Exception $e) {
         throw new CannotPublishException(_("The uploaded image file is broken."));
     }
     # Now all supplied paramters are validated.
     # Do any postprocessing like scaling and rotating
     $image = self::postprocess_image($base64_image, $image, $image_type, $width, $height);
     unset($base64_image);
     # Save the image file. By saving it always from the $image object instead of
     # the original image data (even if not downscaled or rotated), we
     #   - strip JPEG EXIF information, which is intentional for privacy reasons,
     #   - eliminate any data flaws which have may been in the source files.
     $image_uuid = Okapi::create_uuid();
     $imagepath = Settings::get('IMAGES_DIR') . '/' . $image_uuid;
     switch ($image_type) {
//.........这里部分代码省略.........
开发者ID:kratenko,项目名称:oc-server3,代码行数:101,代码来源:add.php


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