zoukankan      html  css  js  c++  java
  • php图片上传

    <input type="file" name="photo" id="photo" class="file"/>




    use IlluminateHttpRequest;
    public function postPublish(Request $request){
    $userid = Auth::user()->pk_id;
    $title = $request->get('col_title');
    $message = $request->get('col_message');
    $file = $request->file('photo');
    if ($file->getClientOriginalExtension() && !in_array($file->getClientOriginalExtension(), $allowed_extensions)) {
    return ['error' => '只能上传png,jpg,gif格式。'];
    }
     $destinationPath = 'storage/uploads/'; //上传位置
    $extension = $file->getClientOriginalExtension();
    $fileName = str_random(10).'.'.$extension;
    $file->move($destinationPath, $fileName);
    $filePath = asset($destinationPath.$fileName);
    //保存到数据库
    if(CompanyInformation::createInformation($userid,$filePath,$title,$message))
    return redirect('/abc');
    else
    return Redirect::back()->withInput()->withError(['error' => '保存失败']);
    }


  • 相关阅读:
    团队博客18
    团队博客17
    团队博客16
    团队博客15
    团队博客14
    团队博客13
    团队博客12
    课堂作业08--MVC框架的具体应用
    课堂作业07--MVC框架
    课堂作业06--23中设计模式
  • 原文地址:https://www.cnblogs.com/xuekun/p/6768036.html
Copyright © 2011-2022 走看看