Support the ongoing development of Laravel.io →
Input Database Forms
Last updated 3 months ago.
0

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.
    }

}
Last updated 3 months ago.
0

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?

Last updated 3 months ago.
0

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);
}
Last updated 5 years ago.
0

Sign in to participate in this thread!

LoadForge

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 Laravel.io - All rights reserved.