2015-10-06 154 views
1

我有我的看法如下代碼:Laravel和懸浮窗上傳圖片

<script type="text/javascript"> 

$("document").ready(function(){ 

    Dropzone.autoDiscover = false; 

    var myDropzone = new Dropzone("#dropzone", { 
     url: "{{url('subir-foto/'.$publicacion->id)}}", 
     maxFilesize: 10,  
     dictDefaultMessage : "Click aquí para subir fotos", 
     previewTemplate : '<div style="display:none"></div>', 
    }); 


    myDropzone.on("sending", function(file) { 
     $("#progress").show(); 
     $("#dropzone").hide();   
    }); 

    myDropzone.on("totaluploadprogress", function(progress) { 
     $("#bar").width(progress+'%'); 
     $("#percent").html(progress.toFixed(2)+'%'); 
     if (progress==100) 
      $("#percent").html('Procesando...');   
    }); 

    myDropzone.on("queuecomplete", function() { 
     $.ajax({ 
      url: "{{URL::to('fotos/'.$publicacion->id)}}",   
      beforeSend: function(){$("#photos").html('<div class="spinner"></div>');}, 
      success: function(jsonData) { 
       $("#photos").html(jsonData); 
      } 
     });  
     myDropzone.removeAllFiles(true); 
     $("#progress").hide(); 
     $("#bar").width('0%'); 
     $("#percent").html("0%");  
     $("#dropzone").show();   
    });  


}); 

</script>  



<div id="progress" style="display:none" class="progress progress-striped active"> 
     <div id="bar" class="progress-bar" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 0%;"> 
     <div id="percent"></div> 
     </div> 
    </div> 


<button id="dropzone" class="btn btn-primary" type="submit">Subir fotos</button> 

而控制器接收圖像:

public function storePhoto($id){ 

    $publicacion = Publicacion::findOrFail($id); 

    //AUTENTIFICADORES DE USUARIO 
    if(Auth::user()->id!=$publicacion->usuario_id && Auth::user()->perfil->id!=1) return Response::view('errors.401', array(), 401); 

    $rules = array(
     'file' => 'required|mimes:jpeg,png,gif|max:10240', 
    ); 
    $validator = Validator::make(Input::all(), $rules); 
    if ($validator->fails()){ 
     return Response::json($validator->messages()->first('file'), 403); 
    }  

    $articulo_id = $publicacion->articulo->id; 

    $file = Input::file('file'); 

    $nuevo_nombre = sha1(time().$file->getClientOriginalName()).'.'.$file->getClientOriginalExtension(); 
    $upload_success = $file->move(upload_path($articulo_id),$nuevo_nombre); 

    Image::make(upload_path($articulo_id).$nuevo_nombre)->fit(150, 100)->save(upload_path($articulo_id)."150x100_".$nuevo_nombre); 
    Image::make(upload_path($articulo_id).$nuevo_nombre)->resize(450, null, function ($constraint) {$constraint->aspectRatio();$constraint->upsize();})->save(upload_path($articulo_id)."450x300_".$nuevo_nombre); 

    $foto = new Foto; 
    $foto->articulo_id = $articulo_id; 
    $foto->nombre = $nuevo_nombre; 
    $foto->save(); 
    $foto->posicion = Foto::where('articulo_id',$articulo_id)->max('posicion')+1; 
    $foto->save();  

    if($upload_success) { 
     return Response::json('success', 200); 
    } else { 
     return Response::json('error', 400); 
    } 
} 

的問題是:

當我嘗試要上傳很多照片,我最多隻能上傳5張照片....在我的本地主機上使用WAMP服務器我沒有這個問題。答案是500錯誤...

請您的反饋。

致以問候

回答

0

可能是你需要增加php的執行時間。將這段代碼保存在你的php文件的頂部或更新你的php ini文件。

ini_set('max_execution_time', 300); //300 seconds = 5 minutes 

還可以增加在Php 5.3.1

Max File Uploads

推出max_file_uploads如果 max_file_uploads = 100不爲你的作品然後搜索suhosin.upload.max_uploads並將其設置爲

suhosin.upload.max_uploads=100 

希望這會有所幫助。