ソースを参照

modify file_upload

stanley-king 9 年 前
コミット
8f628e30c4
3 ファイル変更18 行追加248 行削除
  1. 17 17
      helper/file_upload.php
  2. 0 230
      helper/umeng.php
  3. 1 1
      mobile/control/member_info.php

+ 17 - 17
helper/file_upload.php

@@ -2,59 +2,59 @@
 
 class FileUpload
 {
+    const upload_store_path = BASE_ROOT_PATH . '/data/upload/uploadtmp';
+
     static private function recursive_makedir($path)
     {
         return is_dir($path) or (self::recursive_makedir(dirname($path)) and @mkdir($path));
     }
 
     static private function get_random_string($length) {
-        $str = null;
         $strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
         $max = strlen($strPol)-1;
-        for($i=0;$i<$length;$i++){
+
+        $str = '';
+        for($i=0; $i < $length; $i++) {
             $str.=$strPol[rand(0,$max)];
         }
 
         return $str;
     }
 
-    static public function upload_normal($src_file,$dest_dir,&$file_path)
+    static private function upload_normal($src_file,$dest_dir,&$file_path)
     {
         if(!file_exists($src_file)) {
             return false;
         }
 
         $file_name = strtolower(pathinfo($src_file)['basename']);
-        $sha1 = sha1_file($src_file);
 
-        return self::do_upload($src_file,$sha1,$file_name,$dest_dir,$file_path);
+        return self::do_upload($src_file,$file_name,$dest_dir,$file_path);
+    }
+
+    static public function upload_avatar(&$file_path)
+    {
+        return self::upload_nginx(BASE_AVATAR_PATH,$_SESSION['member_id'],$file_path);
     }
 
-    static public function upload_nginx($dest_dir,$member_id,&$file_path)
+    static private function upload_nginx($dest_dir,$member_id,&$file_path)
     {
         $tmppath = $_POST["file_path"];
-        $sha1 = $_POST["file_sha1"];
         $file_name = $_POST["src_name"];
 
-        return self::do_upload($tmppath,$sha1,$file_name,$dest_dir,$member_id,$file_path);
+        return self::do_upload($tmppath,$file_name,$dest_dir,$member_id,$file_path);
     }
 
-    static private function do_upload($src_path,$file_sig,$file_name,$dest_dir,$member_id,&$file_path)
+    static private function do_upload($src_path,$file_name,$dest_dir,$member_id,&$file_path)
     {
         if (!isset($src_path) || empty($src_path)) {
             return false;
         }
 
-        $upload_tmpdir = '/home/www/shop_develop/data/upload/uploadtmp';
-        $src_path = $upload_tmpdir . $src_path;
-
+        $src_path = self::upload_store_path . $src_path;
         if(!file_exists($src_path)) {
             return false;
         }
-        if (!isset($file_sig) || empty($file_sig)) {
-            @unlink($src_path);
-            return false;
-        }
 
         if (!isset($dest_dir) || empty($dest_dir)) {
             @unlink($src_path);
@@ -68,7 +68,7 @@ class FileUpload
 
         $ext_name = strtolower(pathinfo($file_name)['extension']);
         $dest_fn = strval($member_id) . self::get_random_string(10) . $ext_name;
-        $dest_file = $dest_dir . "/" . sprintf("%03d", $member_id%1000) . "/" . $dest_fn;
+        $dest_file = $dest_dir . "/" . sprintf("%03d", intval(intval($member_id) / 2000)) . "/" . $dest_fn;
 
         if (!self::recursive_makedir(dirname($dest_file))) {
             @unlink($src_path);

+ 0 - 230
helper/umeng.php

@@ -1,230 +0,0 @@
-<?php
-
-
-//todo 确认文件是否删除
-
-/**
- * Created by PhpStorm.
- * User: dell
- * Date: 2016/4/15
- * Time: 16:27
- */
-// 发送类型, android 或者 ios
-class platform_type extends SplEnum
-{
-    const __default = self::unicast;
-    const android = 1;
-    const ios = 2;
-}
-
-// 消息类型
-class msg_type extends SplEnum
-{
-    const __default = self::unicast;
-    const unicast = "unicast";
-    const listcast = "listcast";
-    const filecast = "filecast";
-    const broadcast = "broadcast";
-    const groupcast = "groupcast";
-    const customizedcast = "customizedcast";
-    const alias = "alias";
-    const file_id = "file_id";
-}
-
-class status_code extends SplEnum
-{
-    const __default = self::OK;
-    const OK = 200;
-    const CREATED = 201;
-    const ACCEPTED = 202;
-    const BAD_REQUEST = 400;
-    const UNAUTHORIZED = 401;
-    const FORBIDDEN = 403;
-    const NOT_FOUND = 404;
-    const INTERNAL_SERVICE_ERROR = 500;
-}
-
-class display_type extends SplEnum
-{
-    const __default = self::notification;
-    const notification = "notification";
-    const message = "message";
-}
-
-/**
- * Class upush
- *
- * 友盟推送内容
- */
-class upush
-{
-    const PUSH_URL = "http://msg.umeng.com/api/send";
-    const METHOD = "POST";
-    const APP_MASTER_SECRET = "r6w2a8z9x8zonh7qmk8ds2fvypu02wpj";
-    const APPKEY = "5631efd4e0f55a8770000027";
-
-    private $platform;
-    private $type;
-    private $alias_type;
-    private $alias;
-
-    // 个人信息
-    private $member_id = array();     // 必填选项
-    private $devices_token = array();
-
-    // 通知展示内容
-    private $ticker;
-    private $title;
-    private $text;
-    private $icon;
-    private $largeIcon;
-    private $img;
-    private $sound;
-
-    public function __construct()
-    {
-        $platform = platform_type::android;
-        $type = msg_type::unicast;
-        $ticker = "ticker";
-        $title = "title";
-        $text = "text";
-    }
-
-    // 设置属性
-    private function __set($property_name, $value)
-    {
-        $this->$property_name = $value;
-    }
-
-    // 获取属性
-    private function __get($property_name)
-    {
-        if (isset($this->$property_name)) {
-            return ($this->$property_name);
-        } else {
-            return (NULL);
-        }
-    }
-
-    /**
-     * post发送数据
-     *
-     * @param $url
-     * @param $data_string
-     * @return array
-     */
-    public function http_post_data($url, $data_string)
-    {
-        $ch = curl_init();
-        curl_setopt($ch, CURLOPT_POST, 1);
-        curl_setopt($ch, CURLOPT_URL, $url);
-        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
-        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
-                'Content-Type: application/json; charset=utf-8',
-                'Content-Length: ' . strlen($data_string))
-        );
-        ob_start();
-        curl_exec($ch);
-        $return_content = ob_get_contents();
-        ob_end_clean();
-        $return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
-        return array($return_code, $return_content);
-    }
-
-    /**
-     * 生成签名
-     *
-     * @param $http_method
-     * @param $url
-     * @param $post_body
-     * @param $app_master_secret
-     * @return string
-     */
-    private function make_sign($http_method, $url, $post_body, $app_master_secret)
-    {
-        return strtolower(md5($http_method . $url . json_encode($post_body) . $app_master_secret));
-    }
-
-    // android 打包
-    private function android_pack()
-    {
-        $pack = array();
-        $pack['appkey'] = self::APPKEY;
-        $pack['timestamp'] = time();
-        $pack['type'] = msg_type::unicast;
-        $pack['device_tokens'] = "Aj9AympPsCha5zmPhrV0DbnOZJYF0pqKY5jdKvFy_Hbu";
-//        $pack['device_tokens'] = $this->devices_token;
-        $pack['alias_type'] = "";
-        $pack['alias'] = "";
-        $pack['file_id'] = "";
-        $pack['filter'] = "";
-        $payload = array();
-        $body = array();
-        $body['ticker'] = $this->ticker;
-        $body['title'] = $this->title;
-        $body['text'] = $this->text;
-        $body['icon'] = $this->icon;
-        $body['largeIcon'] = $this->largeIcon;
-        $body['img'] = $this->img;
-        $body['sound'] = $this->sound;
-        $body['builder_id'] = "";
-        $body['play_vibrate'] = "true";
-        $body['play_lights'] = "true";
-        $body['play_sound'] = "true";
-        $body['after_open'] = "go_app";
-        $body['url'] = "";
-        $body['activity'] = "";
-        $body['custom'] = "";
-
-        $extra = array();
-        $extra['key1'] = "key1";
-        $extra['key1'] = "key2";
-        $extra['key1'] = "key3";
-
-        $payload['display_type'] = display_type::message;
-        $payload['body'] = $body;
-        $payload['extra'] = $extra;
-        $pack['payload'] = $payload;
-
-        $policy = array();
-        $policy['start_time'] = "";
-        $policy['expire_time'] = "";
-        $policy['max_send_num'] = "100";
-        $policy['out_biz_no'] = "10001";
-
-//        $pack['policy'] = $policy;
-        $pack['production_mode'] = "false";
-        $pack['description'] = "";
-        $pack['thirdparty_id'] = "";
-
-        return $pack;
-    }
-
-    private function pre_pack()
-    {
-        if (!empty($this->member_id)) {
-
-            $result = Model()->table('device_binding')->where(array('member_id' => array('in', $this->member_id)))->select();
-            foreach ($result as $value) {
-                array_push($this->devices_token, $value['upush_device_token']);
-            }
-            return true;
-        } else {
-            return false;
-        }
-    }
-
-    // android 推送
-    public function android_push()
-    {
-//        $ret = $this->pre_pack();
-//        if ($ret) {
-
-            $pack_body = self::android_pack();
-            $url = self::PUSH_URL . '?sign=' . self::make_sign("POST", self::PUSH_URL, $pack_body, self::APP_MASTER_SECRET);
-            return $this->http_post_data($url, json_encode($pack_body));
-//        } else {
-//            return array(600, '参数输入不完整');
-//        }
-    }
-}

+ 1 - 1
mobile/control/member_info.php

@@ -65,7 +65,7 @@ class member_infoControl extends mbMemberControl
             return self::outerr(errcode::ErrUploadFileFailed);
         }
 
-        $result = FileUpload::upload_nginx(BASE_AVATAR_PATH,$member_id,$file_path);
+        $result = FileUpload::upload_avatar($file_path);
         if($result == false) {
             return self::outerr(errcode::ErrUploadFileFailed);
         }