Ejemplo n.º 1
0
 public function upload()
 {
     $file = $_FILES['file'];
     if (!$file) {
         $this->exit_with_error(1, '无法获取文件,请检查服务器设置。', 400);
     }
     $id = $this->id = isset($_REQUEST['id']) && $_REQUEST['id'] != '' && $_REQUEST['id'] != 'undefined' ? $_REQUEST['id'] : $this->create_id();
     $type = isset($_REQUEST['name']) ? $_REQUEST['name'] : 'ad_url';
     $file_name = $file['name'];
     $md5 = $_REQUEST['md5'];
     $file_md5 = md5_file($file['tmp_name']);
     if ($md5 && $md5 != $file_md5) {
         $this->exit_with_error(2, '文件MD5不一致,上传失败', 408);
     }
     $new_path = $this->get_file_path($type, $file_name, $id);
     //对管理员和广告主后台上传的图片文件自动压缩
     if ($type == 'pic_path') {
         $this->resize_image($new_path, $file, 128, 128);
     }
     if ($type == 'ad_shoot') {
         $this->resize_image($new_path, $file, 0, 400);
     }
     move_uploaded_file($file['tmp_name'], UPLOAD_BASE . $new_path);
     // 记录到log里
     $service = new FileLog();
     $service->insert($id, $type, $new_path, $file_name);
     // 生成反馈
     $result = array('code' => 0, 'msg' => 'uploaded', 'id' => $id, 'url' => UPLOAD_URL . $new_path, 'form' => array());
     if (preg_match('/\\.apk$/i', $new_path)) {
         $package = $this->parse_apk($new_path);
         $result = array_merge($result, $package);
     }
     if (preg_match('/\\.ipa$/i', $new_path)) {
         $package = $this->parse_ipa($new_path);
         $result = array_merge($result, $package);
     }
     $result['form']['id'] = $id;
     $result['form']['pack_md5'] = $file_md5;
     $this->output($result);
 }