【问题标题】:The file must be a file of type: pdf, doc, docx in Laravel 5.1该文件必须是 Laravel 5.1 中的文件类型:pdf、doc、docx
【发布时间】:2016-02-17 04:48:11
【问题描述】:

当我想上传 pdf 或 ms word 文件时,我收到此错误:

文件必须是以下类型的文件:pdf、doc、docx

这是我的控制器:

public function store(BookRequest $request)
{
      $book = new Book();
    $book->title = $request->input('title');
    $book->isbn = $request->input('isbn');
    $book->$author = $request->input('author');
    $book->$description = $request->input('description');
    if($request->hasFile('file'))
    {
        $file = $request->file('file');
        $fileName = date('Y') . "_" . $file->getClientOriginalName();
        $distination_path = 'books/';
        $file->move($distination_path, $fileName);
        $book->book_path = $distination_path . $fileName;
    }
        $book->user_id = \Auth::user()->id;
    $book->save();
    return redirect('/library')->with('message','کتاب موفقانه آپلود شد.')->withErrors('مشکل رخداد');
}

请求:

public function rules()
{
    return [
        'title'=>'required',
        'author'=>'required',
        'isbn'=>'required',
        'file'=>'required|mimes:pdf,doc,docx',
    ];
}

【问题讨论】:

  • 您在正确的型号中调用确切的rules 吗?
  • 解决了。这是第 6,7 行的错误
  • 你能在答案中发布你是如何解决的吗,因为它可能对未来的读者有用
  • 见第 6 行和第 7 行你可以找到 ($)
  • Rastager,太好了,我也错过了 ;) 我已将其添加为答案以完成此问题!

标签: laravel-5.1


【解决方案1】:

回答问题(因为它可能使问题完成)

从$author 和$description 中删除$

即,将以下代码更改为

$book->$author = $request->input('author');
$book->$description = $request->input('description');

喜欢这个

$book->author = $request->input('author');
$book->description = $request->input('description');

希望对以后的读者有所帮助

【讨论】:

    猜你喜欢
    • 2016-03-03
    • 1970-01-01
    • 1970-01-01
    • 2013-07-17
    • 2011-10-01
    • 2018-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多