laravel中的FileNotFoundException

问题描述 投票:1回答:1

在laravel我正在制作一个上传文件的应用程序,用户可以下载同一个文件。

但每次我点击上传我都会收到此错误。

 FileNotFoundException in File.php line 37: The file
 "H:\wamp64\tmp\phpF040.tmp" does not exist

我的观看代码是这样的:

@extends('layouts.app')
@section('content')
@inject('Kala','App\Kala')

<div class="container">
    <div class="row">
 @include('common.errors')
        <form action="/addkala" method="post"  enctype="multipart/form-data">
               <input type="hidden" name="_token" value="{{ csrf_token() }}">
        <input type="text" name="name">
            <input type="text" name="details">
            <input type="file" name="photo" id="photo" >
        <button type="submit">submit</button>
        </form>

    </div>
</div>

@endsection

和我的控制器

public function addkalapost(Request $request)
{


     $rules = [
    'name' => 'required|max:255',
    'details' => 'required',
   'photo' => 'max:1024',
];
$v = Validator::make($request->all(), $rules);
if($v->fails()){

    return redirect()->back()->withErrors($v->errors())->withInput($request->except('photo'));

} else {


    $file = $request->file('photo');

        $fileName = time().'_'.$request->name;
        $destinationPath = public_path().'/uploads';

        $file->move($destinationPath, $fileName);

    $kala=new Kala;

        $kala->name=$request->name;
          return 1;    
    $kala->details=$request->details;

    $kala->pic_name=$fileName;

        $kala->save();

        return redirect()->back()->with('message', 'The post successfully inserted.');

}



}

我将php.ini中的上传最大大小更改为1000M。 PLZ帮助我混淆

php laravel
1个回答
0
投票

我建议您使用文件系统,默认情况下,如果您的文件位于其他位置,您可以在配置/文件系统中创建自己的磁盘,则需要从该处获取文件的存储/应用程序。 'myDisk' => [ 'driver' => 'local', 'root' =>base_path('xyzFolder'), ],

你可以称之为

use Illuminate\Support\Facades\Storage;

$data = Storage::disk('myDisk')->get('myFile.txt');

这显然是获取文件,您可以通过以下laravel文档执行任何其他功能。

© www.soinside.com 2019 - 2024. All rights reserved.