當前位置: 首頁>>代碼示例>>PHP>>正文


PHP utils::parse_str_size方法代碼示例

本文整理匯總了PHP中utils::parse_str_size方法的典型用法代碼示例。如果您正苦於以下問題:PHP utils::parse_str_size方法的具體用法?PHP utils::parse_str_size怎麽用?PHP utils::parse_str_size使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在utils的用法示例。


在下文中一共展示了utils::parse_str_size方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: newrequest

 /**
  * 售後服務申請
  */
 public function newrequest($order_id, $product_id, $action = 'input')
 {
     if ($action == 'save') {
         $mdl_as_request = $this->app_current->model('request');
         $image_upload_arr = array('name' => $_FILES['images']['name'], 'tmp_name' => $_FILES['images']['tmp_name'], 'error' => $_FILES['images']['error'], 'size' => $_FILES['images']['size'], 'type' => $_FILES['images']['type']);
         $ready_upload = array();
         $success_upload_images = array();
         foreach ($image_upload_arr['tmp_name'] as $key => $value) {
             if (!isset($value) || empty($value)) {
                 continue;
             }
             $size = $image_upload_arr['size'][$key];
             $max_conf = $this->app_current->getConf('request_image_size') . 'M';
             $max_size = utils::parse_str_size($max_conf);
             //byte
             if (isset($image_upload_arr['error'][$key]) && !empty($image_upload_arr['error'][$key]) && $image_upload_arr['error'][$key] > 0) {
                 $this->_upload_error($key, '文件上傳失敗!' . $image_upload_arr['error'][$key]);
             }
             if ($size > $max_size) {
                 $this->_upload_error($key, '文件大小不能超過' . $max_conf);
             }
             list($w, $h, $t) = getimagesize($value);
             if (!in_array($t, array(1, 2, 3, 6))) {
                 //1 = GIF,2 = JPG,3 = PNG,6 = BMP
                 $this->_upload_error($key, '文件類型錯誤');
             }
             $ready_upload[] = array('tmp' => $value, 'name' => $image_upload_arr['name'][$key]);
         }
         $mdl_image = app::get('image')->model('image');
         foreach ($ready_upload as $k => $item) {
             $image_id = $mdl_image->store($item['tmp'], null, null, $item['name']);
             $success_upload_images[] = array('target_type' => 'asrequest', 'image_id' => $image_id);
             logger::info('前台售後服務圖片上傳操作' . 'TMP_NAME:' . $item['tmp'] . ',FILE_NAME:' . $item['name']);
         }
         $new_request = array_merge(array('request_id' => $mdl_as_request->apply_id(), 'member_id' => $this->member['member_id'], 'order_id' => $order_id, 'createtime' => time(), 'images' => $success_upload_images, 'product' => array('product_id' => $product_id, 'quantity' => $_POST['product_return_num'])), $_POST['request']);
         $new_request['subject'] = substr(preg_replace('/\\s/', '', $new_request['description']), 0, 100) . '...';
         if ($mdl_as_request->save($new_request)) {
             $this->_send('success', $new_request);
         }
     } else {
         //表單
         $redirect_order = array('app' => 'aftersales', 'ctl' => 'mobile_member', 'act' => 'order');
         if (!$order_id || !$product_id) {
             $this->redirect(array('app' => 'aftersales', 'ctl' => 'mobile_member', 'act' => 'order'));
         }
         $mdl_order = app::get('b2c')->model('orders');
         $order = $mdl_order->dump($order_id, '*', array('items' => array('*')));
         $order_items = $order['items'];
         $order_items = utils::array_change_key($order_items, 'product_id');
         if ($order['member_id'] != $this->member['member_id'] || !isset($order_items[$product_id])) {
             $this->splash('error', $redirect_order, '非法操作!');
         }
         $this->pagedata['order'] = $order;
         $this->pagedata['request_item'] = $order_items[$product_id];
         $goods = app::get('b2c')->model('goods')->getRow('type_id', array('type_id|than' => 0, 'goods_id' => $this->pagedata['request_item']['goods_id']));
         if ($goods) {
             $type_info = app::get('b2c')->model('goods_type')->dump($goods['type_id']);
         }
         $this->pagedata['gtype_assrule'] = $type_info['setting']['assrule'];
         $this->output('aftersales');
     }
 }
開發者ID:yindonghai,項目名稱:msk.com,代碼行數:65,代碼來源:member.php

示例2: save

 public function save($type = 'comment')
 {
     $this->verify_member();
     $this->member = $this->get_current_member();
     $mdl_mcomment = app::get('b2c')->model('member_comment');
     $new_comment_id = $mdl_mcomment->apply_id($type);
     $fipt_idx = -1;
     $max_conf = $this->app->getConf('comment_image_size') . 'M';
     $max_size = utils::parse_str_size($max_conf);
     //byte
     if (!$_POST) {
         $this->end(false, '缺少參數!', 'json_response');
     }
     //新評價
     if ($comment_data = $_POST[$type]) {
         /**
          * $word = array($product_id => $content);.
          */
         foreach ($comment_data['word'] as $goods_id => $word) {
             $product_id = key($word);
             $content = current($word);
             $new_comment = array('comment_id' => $new_comment_id++, 'goods_id' => $goods_id, 'product_id' => $product_id, 'member_id' => $this->member['member_id'], 'order_id' => $_POST['order_id'], 'author_name' => $this->member['uname'], 'createtime' => time(), 'content' => htmlspecialchars($content));
             $new_comment['content'] = preg_replace("/\n/is", '<br>', $new_comment['content']);
             if (empty($new_comment['content']) || trim($new_comment['content']) == '') {
                 continue;
             }
             $new_comment['title'] = substr(preg_replace('/\\s/', '', $new_comment['content']), 0, 100) . '...';
             if ($mark = $comment_data['mark'][$goods_id]) {
                 //評分
                 $new_comment['mark'] = array('mark_star' => floatval($mark), 'goods_id' => $goods_id, 'comment_id' => $new_comment['comment_id']);
             }
             //曬一曬處理
             $image_upload_arr = array('name' => $_FILES[$type]['name'][$product_id], 'tmp_name' => $_FILES[$type]['tmp_name'][$product_id], 'error' => $_FILES[$type]['error'][$product_id], 'size' => $_FILES[$type]['size'][$product_id], 'type' => $_FILES[$type]['type'][$product_id]);
             $ready_upload = array();
             $success_upload_images = array();
             //圖片上傳驗證
             foreach ($image_upload_arr['tmp_name'] as $i => $v) {
                 $fipt_idx++;
                 if (!isset($v) || empty($v)) {
                     continue;
                 }
                 $size = $image_upload_arr['size'][$i];
                 if (isset($image_upload_arr['error'][$i]) && !empty($image_upload_arr['error'][$i]) && $image_upload_arr['error'][$i] > 0) {
                     $this->_upload_error($fipt_idx, '文件上傳失敗!' . $image_upload_arr['error'][$i]);
                 }
                 if ($size > $max_size) {
                     $this->_upload_error($fipt_idx, '文件大小不能超過' . $max_conf);
                 }
                 list($w, $h, $t) = getimagesize($v);
                 if (!in_array($t, array(1, 2, 3, 6))) {
                     //1 = GIF,2 = JPG,3 = PNG,6 = BMP
                     $this->_upload_error($fipt_idx, '文件類型錯誤');
                 }
                 $ready_upload[] = array('tmp' => $v, 'name' => $image_upload_arr['name'][$i]);
             }
             $mdl_image = app::get('image')->model('image');
             foreach ($ready_upload as $k => $item) {
                 $image_id = $mdl_image->store($item['tmp'], null, null, $item['name']);
                 //保存圖片
                 $mdl_image->rebuild($image_id, array('L', 'XS'));
                 //縮略圖片
                 $new_comment['images'][] = array('target_type' => 'comment', 'image_id' => $image_id, 'target_id' => $new_comment['comment_id']);
                 logger::info('前台評價曬一曬圖片上傳操作' . 'TMP_NAME:' . $item['tmp'] . ',FILE_NAME:' . $item['name']);
             }
             if (!$mdl_mcomment->save($new_comment)) {
                 $this->_send('error', '提交失敗!');
             } else {
                 //商品評價計數
                 vmc::singleton('b2c_openapi_goods', false)->counter(array('goods_id' => $goods_id, 'comment_count' => 1, 'comment_count_sign' => md5($goods_id . 'comment_count' . 1 * 1024)));
             }
         }
     }
     //評價追加、回複
     if (isset($_POST['reply']) && !empty($_POST['reply'])) {
         foreach ($_POST['reply'] as $key => $value) {
             $new_reply = array('comment_id' => $new_comment_id++, 'for_comment_id' => $key, 'order_id' => $_POST['order_id'], 'goods_id' => $value['goods_id'], 'product_id' => $value['product_id'], 'member_id' => $this->member['member_id'], 'author_name' => $this->member['uname'], 'createtime' => time(), 'content' => htmlspecialchars($value['content']));
             if (empty($new_reply['content']) || trim($new_reply['content']) == '') {
                 continue;
             }
             $new_reply['title'] = substr(preg_replace('/\\s/', '', $new_reply['content']), 0, 100) . '...';
             if (!$mdl_mcomment->save($new_reply)) {
                 $this->_send('error', '追加評價失敗');
             } else {
                 //更新最後回複時間
                 $mdl_mcomment->update(array('lastreply' => time()), array('comment_id' => $key));
                 //商品評價計數
                 vmc::singleton('b2c_openapi_goods', false)->counter(array('goods_id' => $value['goods_id'], 'comment_count' => 1, 'comment_count_sign' => md5($value['goods_id'] . 'comment_count' . 1 * 1024)));
             }
         }
     }
     $this->_send('success', '提交成功');
 }
開發者ID:noikiy,項目名稱:snk,代碼行數:92,代碼來源:comment.php

示例3: save

 public function save($type = 'comment')
 {
     $this->verify_member();
     $this->member = $this->get_current_member();
     $mdl_mcomment = app::get('b2c')->model('member_comment');
     $new_comment_id = $mdl_mcomment->apply_id($type);
     $redirect = $this->gen_url(array('app' => 'b2c', 'ctl' => 'mobile_comment', 'act' => 'form', 'args' => array($_POST['order_id'])));
     $fipt_idx = -1;
     $max_conf = $this->app->getConf('comment_image_size') . 'M';
     $max_size = utils::parse_str_size($max_conf);
     //byte
     if (!$_POST) {
         $this->splash('error', $redirect, '缺少參數!');
     }
     //新評價
     if ($comment_data = $_POST[$type]) {
         /**
          * $word = array($product_id => $content);.
          */
         foreach ($comment_data['word'] as $goods_id => $word) {
             $product_id = key($word);
             $content = current($word);
             $new_comment = array('comment_id' => $new_comment_id++, 'goods_id' => $goods_id, 'product_id' => $product_id, 'member_id' => $this->member['member_id'], 'order_id' => $_POST['order_id'], 'author_name' => $this->member['uname'], 'createtime' => time(), 'content' => htmlspecialchars($content));
             $new_comment['content'] = preg_replace("/\n/is", '<br>', $new_comment['content']);
             if (empty($new_comment['content']) || trim($new_comment['content']) == '') {
                 continue;
             }
             $new_comment['title'] = substr(preg_replace('/\\s/', '', $new_comment['content']), 0, 100) . '...';
             if ($mark = $comment_data['mark'][$goods_id]) {
                 //評分
                 $new_comment['mark'] = array('mark_star' => floatval($mark), 'goods_id' => $goods_id, 'comment_id' => $new_comment['comment_id']);
             }
             //曬一曬處理
             $image_upload_arr = $comment_data['image'][$product_id];
             //圖片上傳驗證
             foreach ($image_upload_arr as $image_base64) {
                 if (preg_match('/^(data:\\s*image\\/(\\w+);base64,)/', $image_base64, $result)) {
                     $type = $result[2];
                     $ready_tmp_file = tempnam(TMP_DIR, $image_name = 'avatar.' . $type);
                     file_put_contents($ready_tmp_file, base64_decode(str_replace($result[1], '', $image_base64)));
                 } else {
                     continue;
                 }
                 $size = filesize($ready_tmp_file);
                 list($w, $h, $t) = getimagesize($ready_tmp_file);
                 if (!in_array($t, array(1, 2, 3, 6))) {
                     //1 = GIF,2 = JPG,3 = PNG,6 = BMP
                     $this->splash('error', $redirect, '文件上傳失敗.類型錯誤');
                 }
                 $ready_upload[] = $ready_tmp_file;
             }
             $mdl_image = app::get('image')->model('image');
             foreach ($ready_upload as $k => $item) {
                 $image_id = $mdl_image->store($item, null, null, $item['name']);
                 //保存圖片
                 $new_comment['images'][] = array('target_type' => 'comment', 'image_id' => $image_id, 'target_id' => $new_comment['comment_id']);
                 logger::info('前台評價曬一曬圖片上傳操作' . 'TMP_NAME:' . $item['tmp'] . ',FILE_NAME:' . $item['name']);
             }
             if (!$mdl_mcomment->save($new_comment)) {
                 $this->splash('error', $redirect, '提交失敗');
             } else {
                 //商品評價計數
                 vmc::singleton('b2c_openapi_goods', false)->counter(array('goods_id' => $goods_id, 'comment_count' => 1, 'comment_count_sign' => md5($goods_id . 'comment_count' . 1 * 1024)));
             }
         }
     }
     //評價追加、回複
     if (isset($_POST['reply']) && !empty($_POST['reply'])) {
         foreach ($_POST['reply'] as $key => $value) {
             $new_reply = array('comment_id' => $new_comment_id++, 'for_comment_id' => $key, 'order_id' => $_POST['order_id'], 'goods_id' => $value['goods_id'], 'product_id' => $value['product_id'], 'member_id' => $this->member['member_id'], 'author_name' => $this->member['uname'], 'createtime' => time(), 'content' => htmlspecialchars($value['content']));
             if (empty($new_reply['content']) || trim($new_reply['content']) == '') {
                 continue;
             }
             $new_reply['title'] = substr(preg_replace('/\\s/', '', $new_reply['content']), 0, 100) . '...';
             if (!$mdl_mcomment->save($new_reply)) {
                 $this->splash('error', $redirect, '追加評論失敗');
             } else {
                 //更新最後回複時間
                 $mdl_mcomment->update(array('lastreply' => time()), array('comment_id' => $key));
                 //商品評價計數
                 vmc::singleton('b2c_openapi_goods', false)->counter(array('goods_id' => $value['goods_id'], 'comment_count' => 1, 'comment_count_sign' => md5($value['goods_id'] . 'comment_count' . 1 * 1024)));
             }
         }
     }
     $this->splash('success', $redirect, '提交成功!');
 }
開發者ID:yindonghai,項目名稱:msk.com,代碼行數:86,代碼來源:comment.php

示例4: avatar

 /**
  * 會員頭像
  */
 public function avatar($action = false)
 {
     if ($action == 'upload') {
         $redirect_here = array('app' => 'b2c', 'ctl' => 'mobile_member', 'act' => 'avatar');
         $mdl_image = app::get('image')->model('image');
         $image_name = $_FILES['avatar_file']['name'];
         $ready_tmp_file = $_FILES['avatar_file']['tmp_name'];
         $bt_size = filesize($ready_tmp_file);
         $max_conf = $this->app->getConf('member_avatar_max_size') . 'M';
         $max_size = utils::parse_str_size($max_conf);
         //byte
         if ($_FILES['avatar_file']['error']) {
             $this->splash('error', $redirect_here, '頭像上傳失敗!' . $_FILES['avatar_file']['error']);
         }
         if ($bt_size > $max_size) {
             $this->splash('error', $redirect_here, '頭像文件大小不能超過' . $max_conf);
         }
         list($w, $h, $t) = getimagesize($ready_tmp_file);
         if (!in_array($t, array(1, 2, 3, 6))) {
             //1 = GIF,2 = JPG,3 = PNG,6 = BMP
             $this->splash('error', $redirect_here, '文件類型錯誤');
         }
         $image_id = $mdl_image->store($_FILES['avatar_file']['tmp_name'], $this->member['avatar'], null, $image_name);
         logger::info('前台會員頭像上傳操作' . 'TMP_NAME:' . $_FILES['avatar_file']['tmp_name'] . ',FILE_NAME:' . $image_name);
         if (!$image_id) {
             $this->splash('error', $redirect_here, '頭像上傳失敗!');
         }
         $mdl_image->rebuild($image_id, array('S', 'XS'));
         if ($this->app->model('members')->update(array('avatar' => $image_id), array('member_id' => $this->member['member_id']))) {
             $this->splash('success', $redirect_here, '上傳並保存成功!');
         } else {
             $this->splash('error', $redirect_here, '保存失敗!');
         }
     }
     $system_max = get_cfg_var("upload_max_filesize");
     $conf_max = $this->app->getConf('member_avatar_max_size') . 'M';
     if (utils::parse_str_size($conf_max) > utils::parse_str_size($system_max)) {
         $this->pagedata['upload_max'] = $system_max;
     } else {
         $this->pagedata['upload_max'] = $conf_max;
     }
     $this->output();
 }
開發者ID:noikiy,項目名稱:snk,代碼行數:46,代碼來源:member.php

示例5: avatar

 /**
  * 會員頭像.
  */
 public function avatar($action = false)
 {
     $this->title = '設置頭像';
     if ($action == 'upload') {
         $redirect_here = array('app' => 'b2c', 'ctl' => 'mobile_member', 'act' => 'avatar');
         $mdl_image = app::get('image')->model('image');
         $image_base64 = $_POST['avatar_file_base64'];
         if (preg_match('/^(data:\\s*image\\/(\\w+);base64,)/', $image_base64, $result)) {
             $type = $result[2];
             $ready_tmp_file = tempnam(TMP_DIR, $image_name = 'avatar.' . $type);
             file_put_contents($ready_tmp_file, base64_decode(str_replace($result[1], '', $image_base64)));
         }
         $bt_size = filesize($ready_tmp_file);
         $max_conf = $this->app->getConf('member_avatar_max_size') . 'M';
         $max_size = utils::parse_str_size($max_conf);
         //byte
         if ($bt_size > $max_size) {
             $this->splash('error', $redirect_here, '頭像文件大小不能超過' . $max_conf);
         }
         list($w, $h, $t) = getimagesize($ready_tmp_file);
         if (!in_array($t, array(1, 2, 3, 6))) {
             //1 = GIF,2 = JPG,3 = PNG,6 = BMP
             $this->splash('error', $redirect_here, '文件類型錯誤');
         }
         $image_id = $mdl_image->store($ready_tmp_file, $this->member['avatar'], null, $image_name);
         if ($ready_tmp_file) {
             @unlink($ready_tmp_file);
         }
         logger::info('前台會員頭像上傳操作' . 'TMP_NAME:' . $_FILES['avatar_file']['tmp_name'] . ',FILE_NAME:' . $image_name);
         if (!$image_id) {
             $this->splash('error', $redirect_here, '頭像上傳失敗!');
         }
         if ($this->app->model('members')->update(array('avatar' => $image_id), array('member_id' => $this->member['member_id']))) {
             $this->splash('success', $redirect_here, '上傳並保存成功!');
         } else {
             $this->splash('error', $redirect_here, '保存失敗!');
         }
     }
     $system_max = get_cfg_var('upload_max_filesize');
     $conf_max = $this->app->getConf('member_avatar_max_size') . 'M';
     if (utils::parse_str_size($conf_max) > utils::parse_str_size($system_max)) {
         $this->pagedata['upload_max'] = $system_max;
     } else {
         $this->pagedata['upload_max'] = $conf_max;
     }
     $this->output();
 }
開發者ID:yindonghai,項目名稱:msk.com,代碼行數:50,代碼來源:member.php


注:本文中的utils::parse_str_size方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。