2017-12-05 4 views
2

Ich versuche, Bild in Laravel hochladen. Aber wenn ich es hochladen gibt es einen Fehler.Fehler beim Hochladen der Datei in Laravel

Anruf auf eine Elementfunktion getClientOriginalExtension() auf null

Hier ist meine Blade-Datei Form

{{Form::open(array('url' => '/AddNewBlog','id'=>'blogadd' , 
    'method' => 'post','class'=>'form-row','files'=>true, 
    "enctype"=>"multipart/form-data"))}} 

Und hier ist Controller

$imagename_bg = time() . '.' . $photo->getClientOriginalExtension(); 
$destinationPath = public_path('/uploads/blog'); 
$thumb_img = Image::make($photo->getRealPath())->resize(750, 450); 
$thumb_img->save($destinationPath . '/' . $imagename_bg, 80); 
$photo->move($destinationPath, $imagename_bg); 

Bitte helfen Sie mir, wie um dieses Problem zu lösen.

+0

Was ist '$ Foto'? – linktoahref

+0

Dies ist der Name der Variablen, die ich poste –

+0

Sie verwenden interventaion pacakage? – kunal

Antwort

3

Ich kann Ihren Code nicht verstehen. wenn Sie für das Hochladen von Bild suchen und die Größe Intervention Paket mit versuchen Sie dies: -

if($request->hasFile('blogimage')){ 
if (Input::file('blogimage')->isValid()) { 
    $file = Input::file('image'); 
    $img = Image::make($file); 
    $img->resize(400,270); 
    $name = pathinfo($_FILES['image']['name']); 
    $destination = public_path('/uploads/blog'); 
    $ext = $name['extension']; 
    $rand= time().str_random(6).date('h-i-s').'.'.$ext; 
    $img->save($destination.$rand); 
} 
} 

Oder Ohne Intervention pacakge: -

if($request->hasFile('blogimage')){ 
if (Input::file('blogimage')->isValid()) { 
    $file = Input::file('blogimage'); 
    $destination = public_path('/uploads/blog'); 
    $ext= Input::file('blogimage')->getClientOriginalExtension(); 
    $mainFilename =time().str_random(5).date('h-i-s'); 
    $file->move($destination, $mainFilename.".".$ext); 
} 
} 

Hoffe, es hilft!

+0

danke bro seine arbeit. Können Sie mir sagen, wie kann ich dieses Bild verkleinern –

+0

haben Sie Interventionspaket installiert? @ParthSureliya – kunal

+0

ja ich habe diese –

1
$photo = $request->file('file_name'); 
1

Sie müssen nur diese verwenden:

$photo = $request->file("blogimage"); 

statt: das Ihr Problem behoben wird

$photo = $request->input("blogimage") 

Hoffnung!

Verwandte Themen