Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function upload() {
- Log::debug('Upload');
- $sessionId = Session::get ( 'id' );
- $userId = Session::get ( 'userId' );
- $group = Session::get('group');
- $dateTime = $ldate = date ( 'YmdHis' );
- $supplier = Input::get ( 'uploadSupplier' );
- $row_data = 0;
- if ($supplier == - 99) {
- Session::flash ( 'error', 'Please Choose Supplier First' );
- return Redirect::to ( '/showuploadprod' );
- }
- if($group->name != 'ADMIN'){
- $supplier = Session::get('partnerId');
- }
- $file = array (
- 'files' => Input::file ( 'files' )
- );
- $delimiter = "\t";
- $rules = array (
- 'files' => 'required'
- );
- $validator = Validator::make ( $file, $rules );
- if ($validator->fails ()) {
- return Redirect::to ( '/showuploadprod' )->withInput ()->withErrors ( $validator );
- }
- else {
- if (Input::file ( 'files' )->getClientOriginalExtension() != 'txt') {
- return Redirect::to ( '/showuploadprod' )->withInput ()->withErrors ( "Please Upload File .txt" );
- } else {
- if (($handle = fopen ( Input::file ( 'files' ), 'r' )) !== FALSE) {
- while ( ($row = fgetcsv ( $handle, 1000, $delimiter )) !== FALSE ) {
- $row_data++;
- }
- fclose ( $handle );
- }
- $directory = storage_path ( 'uploads');
- $fileName = Input::file ( 'files' )->getClientOriginalName ();
- $file_in = Input::file ( 'files' )->getClientOriginalName ().'_' . $dateTime . '.' . Input::file ( 'files' )->getClientOriginalExtension ();
- $productData = array(
- 'sessionId'=>$sessionId,
- 'userId'=>$userId,
- 'supplier'=>$supplier,
- 'directory'=>$directory.'/'.$file_in,
- 'fileName'=>$fileName,
- 'file_in' => $file_in,
- );
- Input::file('files')->move($directory,$file_in);
- Event::fire('upload_product',array($productData));
- Session::flash ( 'success', 'Process Data Upload' );
- DB::table ( 'log_data_upload' )->insert ( [
- 'type_upload' => 'upload_product',
- 'filename' => $fileName,
- 'file_in' => $file_in,
- 'file_out' => '',
- 'user_id' => $userId,
- 'datetime' => $dateTime,
- 'rows' => $row_data,
- 'status' => 'I',
- 'supplier_id' => $supplier,
- ] );
- return Redirect::to ( '/showuploadprod' );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement