View:
{{ Form::open(['files' => true]) }}
{{ Form::file('my_pdf') }}
{{ Form::submit('Upload') }}
{{ Form::close() }}
Controller:
if (Input::hasFile('my_pdf')) {
// File was successfully uploaded and is now in temp storage.
// Move it somewhere more permanent to access it later.
if (Input::file('my_pdf')->move('path/to/destination/my.pdf')) {
// File successfully saved to permanent storage
} else {
// Failed to save file, perhaps dir isn't writable. Give the user an error.
}
}
iWader said:
View:
{{ Form::open(['files' => true]) }} {{ Form::file('my_pdf') }} {{ Form::submit('Upload') }} {{ Form::close() }}
Controller:
if (Input::hasFile('my_pdf')) { // File was successfully uploaded and is now in temp storage. // Move it somewhere more permanent to access it later. if (Input::file('my_pdf')->move('path/to/destination/my.pdf')) { // File successfully saved to permanent storage } else { // Failed to save file, perhaps dir isn't writable. Give the user an error. } }
Thank you sir @iWader . . . May i know how can I do that using HTML at view page?
if you have issues with what is entering your database, this is what you need to do.
public function store(Request $request)
{
$this->validate($request,[
'file' => 'required',
'author'=>'required',
'name'=>'required',
'image'=>'required|image'
]);
$file = Input::file('image');
$image= \Image::make(\Input::file('image'));
$path= public_path().'/books/';
$image->save($path.$file->getClientOriginalName());
$image->resize(498,580);
$image->save($path.'thumb_'.$file->getClientOriginalName());
$books= new book();
$books->name = $request->input('name');
$books->author = $request->input('author');
$books->image = $file->getClientOriginalName();
$extension = Input::file('file')->getClientOriginalExtension();
$filename = rand(11111111, 99999999). '.' . $extension;
$fullPath = $filename;
$request->file('file')->move(
base_path() . '/public/pdf/', $filename
);
$books->file = $fullPath;
if ($books->save())
{
return redirect()->back()->with('alert','Your book has been uploaded');
}
return redirect()->back()->withErrors($validate);
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community