mercredi 1 mars 2017

Laravel: Undefined value on image upload

First Laravel Project. I building a feature where I can upload an image. Everything what I did is based on this PDF (page 98-101)

My blade.php

<?php echo Form::open(array('url' =>'/product/imgedit','files'=>'true'));
echo 'Adj meg egy új képet';
echo Form::file('image');
echo Form::submit('Upload File');
echo Form::close();?>

My router

Route::get('product/{id}/imgedit', 'InventoryController@imgreq');
Route::post('product/imgedit', 'InventoryController@imgupl');

My Controller:

public function imgreq($id){
    $product = DB::select('select * FROM inventory WHERE barcode = ?', [$id]);;
    return view('productimgupl',['product'=>$product]);
    }

    public function imgupl(){
    $file = $request->file('image');
    //Display File Name
    echo 'File Name: '.$file->getClientOriginalName();
    echo '<br>';
    //Display File Extension
    echo 'File Extension: '.$file->getClientOriginalExtension();
    echo '<br>';
    //Display File Real Path
    echo 'File Real Path: '.$file->getRealPath();
    echo '<br>';
    //Display File Size
    echo 'File Size: '.$file->getSize();
    echo '<br>';
    //Display File Mime Type
    echo 'File Mime Type: '.$file->getMimeType();
    //Move Uploaded File
    $destinationPath = '/media/productimg/';
    $file->move($destinationPath,$file->getClientOriginalName());
    }

Error message:

ErrorException in InventoryController.php line 28: Undefined variable: request

What I did wrong?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire