which type of file you are uploading ?? I can see you have added validation for the file which will except only pdf,doc,docx.
Nov 15, 2015
10
Level 2
Validation Error When uploading a file
When uploading a pdf file I get this error:
The file must be a file of type: pdf, doc, docx.
My controller method:
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('مشکل رخداد');
}
And the Request:
public function rules()
{
return [
'title'=>'required',
'author'=>'required',
'isbn'=>'required',
'description'=>'required|min:10',
'file'=>'required|mimes:pdf,doc,docx',
];
}
thanks
Level 17
@Khudadad If you want to allow files of big size, make sur to edit your upload limit and max request limit settings in your php.ini
More info here: https://laracasts.com/discuss/channels/general-discussion/file-validation-failing-on-larger-files
Please or to participate in this conversation.