/**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  int $mcid
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $mcid_id)
 {
     $this->validate($request, ['file' => 'required']);
     $mcid = MCID::findOrFail($mcid_id);
     $file = $_FILES['file'];
     $fileName = md5($mcid_id . $file['name'] . time());
     $path = str_finish($this->skin_path, '/') . $fileName;
     $content = File::get($file['tmp_name']);
     if (is_image($file['type']) && $file['size'] <= 150 * 1000) {
         list($img_w, $img_h) = getimagesize($file['tmp_name']);
         if ($img_w > 64 || $img_h > 64) {
             $error = "皮肤文件 '{$fileName}' 尺寸不正确.";
         } else {
             $result = $this->manager->saveFile($path, $content);
             if ($result === true) {
                 $skin = Skin::where('mcid_id', $mcid->id)->first();
                 if ($skin == null) {
                     $skin = new Skin();
                 }
                 $skin->mcid_id = $mcid->id;
                 $skin->url = $path;
                 $skin->save();
                 return redirect()->back()->withSuccess("皮肤文件 '{$fileName}' 上传成功.");
             } else {
                 $error = $result ?: "皮肤文件 '{$fileName}' 上传失败.";
             }
         }
     } else {
         $error = "皮肤文件 '{$fileName}' 格式或大小不正确.";
     }
     return redirect()->back()->withErrors([$error]);
 }
Esempio n. 2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     if ($id == 'new') {
         $obj = new Skin();
         $obj->id = $request->get('id');
     } else {
         $obj = Skin::findOrFail($id);
     }
     $obj->name = $request->get('name');
     $obj->save();
     return redirect('/game/skins/' . $obj->id);
 }