2017-06-07 4 views
0

Okay, ich habe ein kleines Problem.Laravel Bilder hochladen

Ich möchte Benutzer in der Lage, Bild in den öffentlichen/Logo-Ordner hochladen und das Bild in einem div anzeigen.

aber ich diese 2 Fehler beim Upload versuchen:

enter image description here

JS:

function submitImage() { 
    var fd = new FormData($("#upload_form")[0]); 
    fd.append('img', $('#img')); 
    $.ajax({ 
     url: 'business', 
     data: fd, 
     dataType: 'json', 
     async: false, 
     type: 'post', 
     processData: false, 
     contentType: false, 
     success: function(data) { 
      $("#image").attr("src", data.url); 
      $('.naviga').append('<div class="alert alert-success">Image Uploaded!<div>'); 
      $(".alert-success").fadeOut(5000); 
     }, 
     error: function(data) { 
      var errors = data.responseJSON; //this will get the errors response data. 
      //show them somewhere in the markup 
      //e.g 
      var errorsHtml = '<div class="alert alert-danger">'; 
      errorsHtml += errors.img[0]; //showing only the first error. 
      errorsHtml += '</div>'; 
      $('.naviga').append('<div class="alert alert-danger">File type not supported! Use files with image extension only!<div>'); //appending to a <div id="form-errors"> 
      $(".alert-danger").fadeOut(5000); 
     } 
    }); 
} 

Controller:

public function image(Requests\ImageRequest $request) { 
    if($request->hasFile('img')) 
    { 
     $image = Input::file('img'); 
     $filename = time() . '.' . $image->getClientOriginalExtension(); 
     $path = public_path('logo/' . $filename); 
     Image::make($image->getRealPath())->resize(200, 200)->save($path); 
     $file = $request->file('img'); 
     return ['url' => url('logo/' . $filename)]; 
    } 
} 

Blade:

<div id="left" class="logo2"> 
    <img class="images" id="image" src="#" alt="Your Logo"/> 
     <form id="upload_form" action="{{ action('[email protected]') }}" enctype="multipart/form-data" role="form" method="POST"> 
     <input type="hidden" name="_token" value="{{ csrf_token() }}"> 
     <input name="img" id="img" class="" data-input="false" type="file" data-buttonText="Upload Logo" data-size="sm" data-badge="false" onchange="submitImage();" /> 
</form> 
    </div> 

Strecke ::

Route::get('/', function() { 
    return view('auth/login'); 
}); 
Route::group(['middleware' => ['auth']], function() { 
    Route::get('tfgm', '[email protected]')->name('tfgm');; 
    Route::get('odeon', '[email protected]')->name('odeon');; 
    Route::get('chronicle', '[email protected]_chronicle')->name('chronicle');; 
    Route::get('smokeyard', '[email protected]')->name('smokeyard');; 
    Route::get('profile/', '[email protected]')->name('profile');; 
    Route::post('update', '[email protected]'); 
    Route::get('create/business', '[email protected]')->name('createBusiness'); 
    Route::post('create', '[email protected]'); 
    Route::get('business/list', '[email protected]')->name('viewBusiness'); 
    Route::get('business/{name}', '[email protected]')->name('displayBusiness'); 
    Route::post('business/test', '[email protected]'); 
}); 
Auth::routes(); 

Route::get('/home', '[email protected]')->name('home'); 

Route::get('/redirect/{provider}', '[email protected]'); 
Route::get('/callback/{provider}', '[email protected]'); 

Wie gefragt Ich habe alle Routen zur Verfügung gestellt, die meine Website

+0

und in der Konsole vereinfachen protokollieren sagt Business/Schablone, also warum? – Przemek

+0

Bitte posten Sie alle zugehörigen Routen in Frage. –

+0

hinzugefügt bitte sehen Sie sich – Przemek

Antwort

0

hat ich glaube, Sie sind vermasselt, während das Bild auf die Daten hinzufügen.

Werfen Sie einen Blick auf this answer, im Grunde können Sie Ihre jquery