php - laravel file upload using custam library

766

"I'm tring to upload file using custome library in laravel file goes in folder successfully but file isn't upload in database

this is my custom library:-

namespace App\Classes;
use Illuminate\Http\Request;

class Hello
{

    static function jai(Request $request)
    {
        if($request->hasfile('name'))
        {

        $image=$request->file('name');
        $new_image=time().'.'.$image->getClientOriginalName();
        $image->move(public_path('image/'),$new_image);

        }

    }
}
?>

and this is my controller store function :-    
        Hello::jai($request);
        $x=$request->all();
        $x['name']=
        $j=Hello::jai($request)->new_image;
        Cruds::create($x);

The file "[000004].jpg" was not uploaded due to an unknown error.

689

Answer

Solution:

Hope this will help.

    public function upload(Request $request){
    if($file = $request->file('file')){
        $name = $file->getClientOriginalName();
        if($file->move('files',$name)){
            $file= new Files();//DB instance modal
            $file->url= $name;
            $file->save();
            return "success";
        }
    }
893

Answer

Solution:

You forgot the file extension. See if this help you.

$image = $request->file('your_input_form_file_name');
$image = time() . '_' . $image->getClientOriginalName() . '.' . $file->getClientOriginalExtension();

$image->move(public_path('images/'), $name);

People are also looking for solutions to the problem: mysql - 'Commands out of sync; you can't run this command now' php sql error while executing multiple queries

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.