app/Http/Controllers/api/FileController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        $file = $request->file('file');
        if($request->hasFile('images'))
        {
            return json_encode([
            'ret'=>400,
            'msg'=>"请上传文件"
         ]);
        }
        $ext = $file->getClientOriginalExtension();
        $filename = md5(uniqid()).".".$ext;
        $path = $request->file->storeAs("/images",$filename);
        dd($path);
    }
public function store ( Request $ request ) { $ file = $ request -> file ( 'file' ) ; if ( $ request -> hasFile ( 'images' ) ) { return json_encode ( [ 'ret' => 400 , 'msg' => " 请上传文件" ] ) ; } $ ext = $ file -> getClientOriginalExtension ( ) ; $ filename = md5 ( uniqid ( ) ) . " . " . $ ext ; $ path = $ request -> file -> storeAs ( " /images " , $ filename ) ; dd ( $ path ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
// echo 8520;die; // echo 1;die; // dd($ext); // dd($filename); // 表单页面传递的name属性