Datei-upload in laravel 4

Habe ich codiert diese in den controller und die Routen-Datei in Laravel 4 und traf sich mit dem Fehler "Call auf eine Memberfunktion move() on a non-object" und

     "Call to a member function getClientOriginalName() on a non-object"

Controller:

class AuthorsController extends BaseController{
    public $restful = true;


    public function post_files()
    {

         $input = Input::all();
        $rules = array(
             'file' => 'image|mime:jpg,gif,png|max:3000',
        );

         $validation = Validator::make($input, $rules);

         if ($validation->fails())
         {
           return Response::make($validation->errors->first(), 400);
         }


        $file = Input::file('file'); //your file upload input field in the form should be named 'file'

        $destinationPath = 'public/uploads/'.str_random(8);
        //$filename = $file->getClientOriginalName();
        $filename = $file['name'];
        //$extension =$file->getClientOriginalExtension(); //if you need extension of the file
        $uploadSuccess = Input::file('file')->move($destinationPath, $filename);



        if( $uploadSuccess ) {
           return Response::json('success', 200); //or do a redirect with some message that file was uploaded
        } else {
           return Response::json('error', 400);
        }
    }

}

Routen:

Route::post('post_files','AuthorsController@post_files');

Zeigen die view-Datei mit dem Formular enthalten
I m Vorbeigehen eine Datei von postman-rest-api-tester
Ist die Datei gesendet? versuchen var_dump($_FILES) in einer controller action

InformationsquelleAutor richa | 2013-08-09

Schreibe einen Kommentar