public static function getHtml($url) { $client = new Client(); $response = $client->get($url, ['verify' => false, 'timeout' => 10]); if ($response->getStatusCode() != 200) { $error = '%s: Bad HTTP response code, url is %s, status code is %d.'; $error = sprintf($error, __METHOD__, $url, $response->getStatusCode()); Log::error($error); throw new \Exception($error, 0); } return $response->getBody()->__toString(); }
public function uploadFile($file_category_name, $input_name = "file", Request $request) { $file_max_size = $this->iniGetBytes('upload_max_filesize'); $post_max_size = $this->iniGetBytes('post_max_size'); if ($_SERVER['CONTENT_LENGTH'] > $post_max_size) { abort(403, "The file is too big. There is a post limit of " . ini_get('post_max_size') . " on the server."); } $file_category = FileCategory::where('name', $file_category_name)->first(); if (!$file_category) { $file_category = FileCategory::create(['name' => $file_category_name]); } $this->file_category_id = $file_category->id; $this->title = $request->input('title'); $file = $request->file($input_name); if (!$file) { return false; } $size = $file->getSize(); if ($size > $file_max_size) { abort(403, "The file is too big. Files should be less than " . ini_get('upload_max_filesize') . "."); } try { $mimeType = $file->getMimeType(); } catch (\Exception $e) { \Log::error($e->getMessage()); //Sometimes if the file is too big, but it will catch it later on when you try to move the file } if (isset($mimeType) && substr($mimeType, 0, 5) == 'image') { try { $img = Image::make($file)->resize(1920, null, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); }); } catch (Exception $e) { abort(400, 'There was an error uploading and resizing the image'); } catch (NotReadableException $e) { abort(403, "Unable to read image from file"); } $this->image = true; $filename = md5($img->response()) . ".png"; $img->save(getcwd() . "/uploads/" . $this->fileCategory->name . "/{$filename}"); } else { $filename = md5($file) . "." . $file->getClientOriginalExtension(); $file->move(getcwd() . "/uploads/" . $this->fileCategory->name, $filename); $this->image = false; } $this->filename = $filename; }
public function addCampaignMembership() { $relationship = new Relationship(); $relationship->source_type = 'App\\Campaign'; $relationship->source_id = \Session::get('campaign')->id; $relationship->sibling_type = $this->referenceClass; $relationship->sibling_id = $this->id; try { $relationship->save(); } catch (Exception $e) { \Log::error('Could not register ' . $this->referenceClass . ': ' . $this->id . ' with campaign ' . \Session::get('campaign')->id . ': Error message is ' . $e->getMessage()); } }
/** * @param \Exception $e */ protected function logException(\Exception $e) { \Log::error($e->getMessage() . ' in ' . $e->getFile() . ':' . $e->getLine() . "\n" . $e->getTraceAsString() . "\n" . str_repeat('=', 80) . "\n"); }