/**
  * Store a newly created resource in storage.
  *
  * @param  CreatePostRequest $request
  * @return Response
  */
 public function store(CreatePostRequest $request, $category_id)
 {
     // save post
     $post = new Post();
     $post->fill($request->all());
     $post->category_id = $category_id;
     $post->save();
     // if have attachment, create the attachment record
     if ($request->hasFile('attachment')) {
         // generate filename based on UUID
         $filename = Uuid::generate();
         $extension = $request->file('attachment')->getClientOriginalExtension();
         $fullfilename = $filename . '.' . $extension;
         // store the file
         Image::make($request->file('attachment')->getRealPath())->resize(null, 640, function ($constraint) {
             $constraint->aspectRatio();
             $constraint->upsize();
         })->save(public_path() . '/attachments/' . $fullfilename);
         // attachment record
         $attachment = new Attachment();
         $attachment->post_id = $post->id;
         $attachment->original_filename = $request->file('attachment')->getClientOriginalName();
         $attachment->filename = $fullfilename;
         $attachment->mime = $request->file('attachment')->getMimeType();
         $attachment->save();
     }
     return redirect('category/' . $category_id . '/posts');
 }
示例#2
0
 public function store($employeeId, Request $request)
 {
     $this->validate($request, ['name' => 'required', 'file' => 'required']);
     $attachment = new Attachment();
     $attachment->employee_id = $employeeId;
     $attachment->name = $request->name;
     $attachment->location = $this->upload($request->name);
     $attachment->save();
     return redirect()->to('/hr/employee/' . $employeeId);
 }
示例#3
0
 public function addLogo($file)
 {
     $imageName = $this->id . '-' . time() . '.' . $file->getClientOriginalExtension();
     $attachment = new Attachment();
     $attachment->type = 'image';
     $attachment->file_src = 'images/uploads/branches/' . $imageName;
     $attachment->filename = $imageName;
     $attachment->save();
     $file->move(base_path() . '/public/images/uploads/branches', $imageName);
     $this->pictures()->save($attachment);
 }
示例#4
0
 public function addBackgroundImage($file)
 {
     $imageName = $this->id . '-' . time() . '.' . $file->getClientOriginalExtension();
     $attachment = new Attachment();
     $attachment->type = 'image';
     $attachment->file_src = 'images/uploads/dockets/' . $imageName;
     $attachment->filename = $imageName;
     $attachment->save();
     $file->move(base_path() . '/public/images/uploads/dockets', $imageName);
     $this->pictures()->save($attachment);
     $this->pictures()->first()->resize(1000, 2000);
     $this->pictures()->first()->saveDimensions();
 }
示例#5
0
 public function addAttachment($file)
 {
     $imageName = 'comment-' . $this->id . '-' . time() . '.' . $file->getClientOriginalExtension();
     $filetype = strtolower($file->getClientOriginalExtension());
     $attachment = new Attachment();
     if ($filetype == 'jpg' || $filetype == 'jpeg' || $filetype == 'png' || $filetype == 'gif') {
         $attachment->type = 'image';
     } else {
         $attachment->type = 'other';
     }
     $attachment->file_src = 'images/uploads/attachments/' . $imageName;
     $attachment->filename = $imageName;
     $attachment->save();
     $file->move(base_path() . '/public/images/uploads/attachments', $imageName);
     $this->attachments()->save($attachment);
 }
示例#6
0
 public function store(AttachmentRequest $request, Attachment $attachment)
 {
     if (!Helper::getMode()) {
         return redirect()->back()->withErrors(config('constants.DISABLE_MESSAGE'));
     }
     $filename = uniqid();
     $data = $request->all();
     if ($request->hasFile('file')) {
         $extension = $request->file('file')->getClientOriginalExtension();
         $file = $request->file('file')->move('uploads/attachment_files/', $filename . "." . $extension);
         $data['file'] = $filename . "." . $extension;
     }
     $data['user_id'] = Auth::user()->id;
     $attachment->fill($data);
     $attachment->save();
     $activity = 'Attached a file on a ' . $request->input('belongs_to');
     Activity::log($activity);
     return redirect()->back()->withSuccess(config('constants.SAVED'));
 }
示例#7
0
 public function uploadFile(Request $request)
 {
     // copy($_FILES['file']['tmp_name'], '/files/'.$_FILES['file']['name']);
     $file = $request->file('file');
     $file->move('uploads/files/' . $request->name, $_FILES['file']['name']);
     $array = array('filelink' => asset('uploads/files/' . $request->name . '/' . $_FILES['file']['name']), 'filename' => $_FILES['file']['name']);
     $attachment = new Attachment();
     $attachment->name = $request->name;
     $attachment->file = $_FILES['file']['name'];
     $attachment->type = 'pdf';
     $attachment->save();
     echo stripslashes(json_encode($array));
 }
 public function update($id, Request $request)
 {
     $validator = Validator::make($request->all(), ['title' => 'required | min:3', 'headline' => 'sometimes|min:3', 'body' => 'sometimes | min:3', 'attachments' => 'required', 'published' => 'required|date', 'expires' => 'sometimes|after:' . $request->published]);
     if ($validator->passes()) {
         $post = Update::withTrashed()->find($id);
         $post->title = $request->title;
         $post->content = $request->body;
         $post->published_on = $request->published;
         $post->headline = $request->headline;
         if (isset($request->expires)) {
             $post->expires_on = $request->expires;
         }
         $post->category_id = $request->category;
         if ($post->save()) {
             if ($request->delete) {
                 foreach ($request->delete as $deletion) {
                     $attachment = Attachment::find($deletion);
                     $attachment->delete();
                 }
             }
             $request->featured = $request->featured == '' ? null : $request->featured;
             $post->featured = $request->featured;
             $post->save();
             if ($request->destroy) {
                 $post->delete();
             } else {
                 if (!is_null($post->deleted_at)) {
                     $post->restore();
                 }
             }
             $files = $request->file('attachments');
             if (count($files)) {
                 if (!is_dir($this->upload_dir . $post->id)) {
                     mkdir($this->upload_dir . $post->id);
                 }
                 $success = true;
                 foreach ($files as $file) {
                     if (!is_null($file) && $file->isValid()) {
                         if ($file->move($this->upload_dir . $post->id, $file->getClientOriginalName())) {
                             $attachment = new Attachment();
                             $attachment->filename = $file->getClientOriginalName();
                             $attachment->size = $file->getClientSize();
                             $attachment->update_id = $post->id;
                             $attachment->type = pathinfo($this->upload_dir . $post->id . '/' . $file->getClientOriginalName(), PATHINFO_EXTENSION);
                             $attachment->save();
                         } else {
                             $success = false;
                         }
                     }
                 }
                 if ($success) {
                     return redirect('about/galleries/' . $post->id . '/edit');
                 }
             }
             return redirect('about/galleries');
         } else {
             return 'Error';
         }
     } else {
         return redirect('about/galleries/' . $post->id . '/edit')->withInput();
     }
 }
示例#9
0
 public function send(Request $request)
 {
     $validator = Validator::make($request->all(), ['contact_id' => 'required', 'to' => 'required', 'subject' => 'required', 'body' => 'required']);
     if ($validator->passes()) {
         if ($request->file('attachment')) {
             $file = $request->file('attachment');
             $destinationPath = 'uploads/' . str_random(8) . "-" . time();
             $filename = $file->getClientOriginalName();
             //$extension = $file->getClientOriginalExtension();
             $uploadSuccess = $request->file('attachment')->move($destinationPath, $filename);
             if ($uploadSuccess) {
                 $attachment = new Attachment();
                 $attachment->attachment_filename = $destinationPath . "/" . $filename;
                 $attachment->save();
             }
         }
         foreach ($request->input('contact_id') as $contact_id) {
             if ($contact_id > 0) {
                 $message_log = new Message();
                 $message_log->contact_id = $contact_id;
                 $message_log->user_id = auth()->user()->id;
                 $message_log->message_type_id = $this->message_type->where('message_type_name', 'LIKE', '%Email%')->get()->first()->id;
                 $message_log->school_id = $request->input('school_id');
                 if (isset($attachment)) {
                     $message_log->attachment_id = $attachment->id;
                 }
                 $contents = "";
                 $body = $request->input('body');
                 if (isset($attachment)) {
                     //$body .= "\n\nAttachment: ".$attachment->fileLink();
                 }
                 $body .= "\n\n____________________\n" . auth()->user()->username . "\nBrentwood University Counselling";
                 $contents .= "To: " . $request->input('to') . "\n";
                 $contents .= "From: " . auth()->user()->email . "\n";
                 $contents .= "Subject: " . $request->input('subject') . "\n\n";
                 $contents .= "Message: " . $body;
                 $message_log->contents = $contents;
                 $message_log->save();
             }
         }
         $body = preg_replace('/\\n{2,}/', "</p><p>", trim($body));
         $body = preg_replace('/\\n/', '<br>', $body);
         $body = "<p>{$body}</p>";
         $data = ['body' => $body];
         //$sent_to = $request->input('to');
         if (strpos($request->input('to'), ',') !== false) {
             $to_array = explode(',', $request->input('to'));
             foreach ($to_array as $sent_to) {
                 if (isset($attachment)) {
                     Email::sendEmail(trim($request->input('to')), $request->input('subject'), $data, $attachment);
                 } else {
                     Email::sendEmail(trim($request->input('to')), $request->input('subject'), $data);
                 }
                 $this->addEmailAddress($sent_to);
             }
         } else {
             if (isset($attachment)) {
                 Email::sendEmail(trim($request->input('to')), $request->input('subject'), $data, $attachment);
             } else {
                 Email::sendEmail(trim($request->input('to')), $request->input('subject'), $data);
             }
             $this->addEmailAddress($request->input('to'));
         }
         return redirect()->to('/')->with(['success' => 'Email to <span class="mono">' . $request->input('to') . '</span> sent']);
     } else {
         return redirect()->back()->withInput()->withErrors($validator->messages());
     }
 }
 /**
  * Metodo para subir un archivo al servidor y guardarlo en la base de datos
  * @param _FILE $file archivo que se esta subiendo
  * @param Attachment Entidad con toda la informacion de un archivo a guardar
  * @return JSON respuesta del proceso de carga de archivo
  */
 public static function uploadAttachmentIntoDB($file, $attachment = '')
 {
     $att = $attachment;
     if (!$att) {
         $att = new Attachment();
     }
     $f = $file;
     if ($f) {
         $att->name = $f->getClientOriginalName();
         $att->mime = $f->getMimeType();
         $att->size = $f->getSize();
         $attfile = file_get_contents($f->getRealPath());
         if ($att->encode == 'base64') {
             $attfile = base64_encode(file_get_contents($f->getRealPath()));
         }
         $att->file = $attfile;
         $att->save();
         return Response::json(array('valid' => true));
     } else {
         return Response::json(array('valid' => false, 'error' => array($f->getError(), $f->getErrorMessage())));
     }
 }
示例#11
0
 public function store(Request $request, $id = null)
 {
     $validator = Validator::make($request->all(), $this->message->rules);
     if ($validator->passes()) {
         if (!isset($id)) {
             $save_attachment = true;
         } else {
             if (isset($id)) {
                 $attachment_check = $this->message->find($id);
                 if (!$attachment_check->attachment_id) {
                     $save_attachment = true;
                 } else {
                     $save_attachment = false;
                 }
             } else {
                 $save_attachment = false;
             }
         }
         if ($save_attachment && $request->file('attachment')) {
             $file = $request->file('attachment');
             $destinationPath = 'uploads/' . str_random(8) . "-" . time();
             $filename = $file->getClientOriginalName();
             //$extension = $file->getClientOriginalExtension();
             $uploadSuccess = $request->file('attachment')->move($destinationPath, $filename);
             if ($uploadSuccess) {
                 $attachment = new Attachment();
                 $attachment->attachment_filename = $destinationPath . "/" . $filename;
                 $attachment->save();
             }
         }
         foreach ($request->input('contact_id') as $contact_id) {
             if ($contact_id > 0) {
                 if (isset($id)) {
                     $message = $this->message->find($id);
                 } else {
                     $message = new Message();
                 }
                 $message->contact_id = $contact_id;
                 $message->user_id = auth()->user()->id;
                 $message->message_type_id = $request->input('message_type_id');
                 $message->school_id = $request->input('school_id');
                 $message->contents = $request->input('contents');
                 if (isset($attachment)) {
                     $message->attachment_id = $attachment->id;
                 }
                 $message->save();
             }
         }
         return redirect()->to('/')->with(['success' => 'Log <span class="mono">' . sprintf('%04d', $message->id) . '</span> saved']);
     } else {
         return redirect()->back()->withInput()->withErrors($validator->messages());
     }
 }
示例#12
0
 function save_attachments(&$files, $article_id)
 {
     $files = Input::file('attachment_name');
     foreach ($files as $file) {
         if (!empty($file) && $file->isValid()) {
             $attachment = new Attachment();
             $current_time = Carbon::now();
             //$attachment->name = $current_time.'.'.($file->getClientOriginalExtension());
             $current_time_str = preg_replace('/\\s+/', '', $current_time);
             $current_time_str = preg_replace('/-/', '', $current_time_str);
             $current_time_str = preg_replace('/:/', '', $current_time_str);
             $attachment->name = $current_time_str . '_' . $file->getClientOriginalName();
             $file->move('attachments/', $attachment->name);
             $attachment->path = 'attachments/' . $attachment->name;
             $attachment->article_id = $article_id;
             $attachment->save();
         }
     }
 }
示例#13
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id, Request $request)
 {
     $post = Update::withTrashed()->find($id);
     $post->title = $request->title;
     $post->content = $request->body;
     $post->published_on = $request->published;
     $post->headline = $request->headline;
     if (isset($request->expires)) {
         $post->expires_on = $request->expires;
     }
     $post->category_id = $request->category;
     if ($post->save()) {
         if ($request->delete) {
             foreach ($request->delete as $deletion) {
                 $attachment = Attachment::find($deletion);
                 $attachment->delete();
             }
         }
         $request->featured = $request->featured == '' ? null : $request->featured;
         $post->featured = $request->featured;
         $post->save();
         if ($request->destroy) {
             $post->delete();
         } else {
             if (!is_null($post->deleted_at)) {
                 $post->restore();
             }
         }
         $files = $request->file('attachments');
         if (count($files)) {
             if (!is_dir($this->upload_dir . $post->id)) {
                 mkdir($this->upload_dir . $post->id);
             }
             $success = true;
             foreach ($files as $file) {
                 if (!is_null($file) && $file->isValid()) {
                     if ($file->move($this->upload_dir . $post->id, $file->getClientOriginalName())) {
                         $attachment = new Attachment();
                         $attachment->filename = $file->getClientOriginalName();
                         $attachment->size = $file->getClientSize();
                         $attachment->update_id = $post->id;
                         $attachment->type = pathinfo($this->upload_dir . $post->id . '/' . $file->getClientOriginalName(), PATHINFO_EXTENSION);
                         $attachment->save();
                     } else {
                         $success = false;
                     }
                 }
             }
             if ($success) {
                 return redirect('academylife/sports-news/' . $post->id . '/edit');
             }
         }
         return redirect('academylife/sports-news');
     } else {
         return 'Error';
     }
 }