2017-05-08 4 views
0

Jedesmal, wenn ein chunked Hochladen hochgeladen wird, werden alle Stücke mehrfach in der DBChunk Hochladen mehrere einfügen

jeder Chunk = 1 Einsatz in die Datenbank

protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null) 
{ 
    $file = parent::handle_file_upload($uploaded_file, $name, $size, $type, $error, $index, $content_range); 

    if (empty($file->error)) { 

     DB::table('test')->insert([ 
      'name' => json_encode($file) 
     ]); 


    } 
    return $file; 
} 

Antwort

0

Ordnung eingesetzt sind, I das Problem gelöst.

Um mehrere Einsatz zu vermeiden, wenn Klumpen mit uploads

protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, 
             $index = null, $content_range = null) 
{ 
    $file = parent::handle_file_upload(
     $uploaded_file, $name, $size, $type, $error, $index, $content_range 
    ); 


    // check if a file is needed to be chunked, 
    // if file is null, file does not need to be chunked otherwise file should be chunked upload 
    if(! is_null($content_range)) 
    { 
     // ex. the file is 1mb then last chunk would be 999,999 
     $last_chunk = (int) $content_range[2]; 
     // get the filesize of the entire 
     $filesize = (int) $content_range[3]; 

     // get the last chunk then add 1 to it and compare it to the filesize 
     if(($last_chunk + 1) === $filesize) 
     { 
      // db actions like insert to db or update something 
     } 
    } else { 

     // other things 
    } 


    return $file; 
}