Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. public function upload() {
  2. Log::debug('Upload');
  3. $sessionId = Session::get ( 'id' );
  4. $userId = Session::get ( 'userId' );
  5. $group = Session::get('group');
  6. $dateTime = $ldate = date ( 'YmdHis' );
  7. $supplier = Input::get ( 'uploadSupplier' );
  8. $row_data = 0;
  9. if ($supplier == - 99) {
  10. Session::flash ( 'error', 'Please Choose Supplier First' );
  11. return Redirect::to ( '/showuploadprod' );
  12. }
  13. if($group->name != 'ADMIN'){
  14. $supplier = Session::get('partnerId');
  15. }
  16.  
  17. $file = array (
  18. 'files' => Input::file ( 'files' )
  19. );
  20. $delimiter = "\t";
  21. $rules = array (
  22. 'files' => 'required'
  23. );
  24. $validator = Validator::make ( $file, $rules );
  25. if ($validator->fails ()) {
  26. return Redirect::to ( '/showuploadprod' )->withInput ()->withErrors ( $validator );
  27. }
  28. else {
  29. if (Input::file ( 'files' )->getClientOriginalExtension() != 'txt') {
  30. return Redirect::to ( '/showuploadprod' )->withInput ()->withErrors ( "Please Upload File .txt" );
  31. } else {
  32. if (($handle = fopen ( Input::file ( 'files' ), 'r' )) !== FALSE) {
  33. while ( ($row = fgetcsv ( $handle, 1000, $delimiter )) !== FALSE ) {
  34. $row_data++;
  35. }
  36. fclose ( $handle );
  37. }
  38. $directory = storage_path ( 'uploads');
  39. $fileName = Input::file ( 'files' )->getClientOriginalName ();
  40. $file_in = Input::file ( 'files' )->getClientOriginalName ().'_' . $dateTime . '.' . Input::file ( 'files' )->getClientOriginalExtension ();
  41. $productData = array(
  42. 'sessionId'=>$sessionId,
  43. 'userId'=>$userId,
  44. 'supplier'=>$supplier,
  45. 'directory'=>$directory.'/'.$file_in,
  46. 'fileName'=>$fileName,
  47. 'file_in' => $file_in,
  48. );
  49.  
  50. Input::file('files')->move($directory,$file_in);
  51.  
  52. Event::fire('upload_product',array($productData));
  53. Session::flash ( 'success', 'Process Data Upload' );
  54.  
  55.  
  56. DB::table ( 'log_data_upload' )->insert ( [
  57. 'type_upload' => 'upload_product',
  58. 'filename' => $fileName,
  59. 'file_in' => $file_in,
  60. 'file_out' => '',
  61. 'user_id' => $userId,
  62. 'datetime' => $dateTime,
  63. 'rows' => $row_data,
  64. 'status' => 'I',
  65. 'supplier_id' => $supplier,
  66. ] );
  67.  
  68. return Redirect::to ( '/showuploadprod' );
  69. }
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement