0

I have the following store method for upload a file.

public function store()
    {
        //

        $rules = [];
        $validator = Validator::make(Input::all(), $rules);

        // if the validator fails, redirect back to the form
        if ($validator->fails()) {
            return Redirect::back()
                ->withErrors($validator) // send back all errors to the login form
                ->withInput();
        } else {

            $klas = new Klas;
            $klas ->title =  Input::get('title');
            if (Input::get('active') === 'yes') {
                $klas ->active = 1;
            } else {
                $klas ->active = 0;
            }


            $extension = 'png';
            $directory = public_path() . '/uploads/klassen';
            $filename = Input::get('title').".{$extension}";

            $upload_success = Input::file('image',$directory,$filename);

            //Upload the file
            if($upload_success){
                $klas->image = $filename;
                $klas -> save();
                $klassen = DB::table('klas')->get();

                return View::make('klas.index',compact('klassen'));
            }



        }
    }

My 'klas' is succefully saved into the database also with the correct file name. But the file is not uploaded? I've set the public , uploads and klassen folder to read write for everyone already.

Any help ?

1 Answer 1

1

You have to move the file to the target directory:

$file = Input::file('image');
$file->move($directory, $filename);

I'm not sure if taking the 2nd and 3rd argument like you're doing now works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.