/** * upload avatar * @param $file * @param $user_id * @return mixed */ public static function saveAvatar($file, $user_id) { $now_date = str_replace('/', '_', date('d/m/Y')); $filename = $file->getClientOriginalName(); $filename = File::removesign($filename); $filename = File::removespace($filename); $newfilename = $now_date . '_' . rand(1, 99999) . '_' . $filename; Storage::put('avatar/' . $newfilename, file_get_contents($file->getRealPath())); //$upload_success = $file->move($destinationPath, $newfilename); $path = storage_path('uploads/avatar/' . $newfilename); $img = Image::make($path); // resize image instance $img->resize(320, 240); $savefile = new File(['name' => $newfilename, 'mine' => $file->getClientMimeType(), 'original_filename' => $file->getClientOriginalName(), 'nguoiupload_id' => $user_id]); $savefile->save(); return $savefile->id; }
public function send() { // get input $to = \Input::get('nguoinhan'); $tos = preg_split("/[\\s;]+/", $to); $cc = \Input::get('nguoinhankhac'); $ccs = preg_split("/[\\s;]+/", $cc); $subject = \Input::get('tieude'); $message = \Input::get('noidung'); //echo '<pre>'; //print_r($ccs); //$toEmails = array('*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**'); // has file if (\Input::hasFile('attachment')) { $now_date = str_replace('/', '_', date('d/m/Y')); $files = \Input::file('attachment'); $newnamefiles = array(); foreach ($files as $file) { $destinationPath = 'uploads'; $filename = $file->getClientOriginalName(); $filename = File::removesign($filename); $filename = File::removespace($filename); $newfilename = $now_date . '_' . rand(1, 99999) . '_' . $filename; $upload_success = $file->move($destinationPath, $newfilename); array_push($newnamefiles, $newfilename); } $path = array(); foreach ($newnamefiles as $value) { $filepath = 'uploads/' . $value; array_push($path, $filepath); } // không cc if ($ccs[0] == '') { \Mail::send('emails.mail', array('user_message' => \Input::get('noidung')), function ($message) use($path, $tos, $ccs, $subject) { $message->from('*****@*****.**', 'Lê Thanh Thái'); $message->to($tos)->subject($subject); $size = count($path); for ($i = 0; $i < $size; $i++) { $message->attach($path[$i]); } }); return \Redirect::route('email.send')->with('message', 'Gửi Thành Công!'); } else { \Mail::send('emails.mail', array('user_message' => \Input::get('noidung')), function ($message) use($path, $tos, $ccs, $subject) { $message->from('*****@*****.**', 'Lê Thanh Thái'); $message->to($tos)->cc($ccs)->subject($subject); $size = count($path); for ($i = 0; $i < $size; $i++) { $message->attach($path[$i]); } }); return \Redirect::route('email.send')->with('message', 'Gửi Thành Công!'); } } else { if ($ccs[0] == '') { \Mail::send('emails.mail', array('user_message' => \Input::get('noidung')), function ($message) use($tos, $ccs, $subject) { $message->from('*****@*****.**', 'Lê Thanh Thái'); $message->to($tos)->subject($subject); }); return \Redirect::route('email.send')->with('message', 'Gửi Thành Công!'); } else { \Mail::send('emails.mail', array('user_message' => \Input::get('noidung')), function ($message) use($tos, $ccs, $subject) { $message->from('*****@*****.**', 'Lê Thanh Thái'); $message->to($tos)->cc($ccs)->subject($subject); }); return \Redirect::route('email.send')->with('message', 'Gửi Thành Công!'); } } //end send }