acdsc - PHP Online
Form of PHP Sandbox
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of acdsc.php
- <?php
- class ScreenShot
- {
- const URL = 'https://mini.s-shot.ru/';
- private $fileName;
- private $sizeW;
- private $sizeH;
- private $extension;
- private $url;
- private $content;
- private function __construct($fileName, $url, $sizeW, $sizeH, $extension)
- {
- $this->fileName = $fileName;
- $this->url = $url;
- $this->sizeW = $sizeW;
- $this->sizeH = $sizeH;
- $this->extension = $extension;
- }
- private function validate()
- {
- if (empty($this->fileName) || !is_string($this->fileName) || mb_strlen($this->fileName) < 1) {
- return false;
- }
- if (empty($this->url) || !is_string($this->url) || mb_strlen($this->url) < 3) {
- return false;
- }
- if (!is_int($this->sizeW) || $this->sizeW < 1 || $this->sizeW > 8192) {
- return false;
- }
- if (!is_int($this->sizeH) || $this->sizeH < 0) {
- return false;
- }
- if ($this->extension !== 'jpeg' && $this->extension !== 'png') {
- return false;
- }
- return true;
- }
- public static function make($fileName, $url, $sizeW, $sizeH = 0, $extension = 'jpeg')
- {
- $instance = new self($fileName, $url, $sizeW, $sizeH, $extension);
- if ($instance->validate()) {
- return $instance;
- }
- throw new \Exception('Error, check parameters', 0001);
- }
- private function getUrl()
- {
- $url = self::URL;
- $url .= "/{$this->sizeW}x{$this->sizeH}/{$this->extension}/{$this->sizeW}/{$this->fileName}";
- $url .= "/?{$this->url}";
- return $url;
- }
- private function getScreenShot()
- {
- $this->content = file_get_contents($this->getUrl());
- }
- public function save($fileFullPath)
- {
- if (empty($this->content)) {
- $this->getScreenShot();
- }
- if (!file_exists($fileFullPath)) {
- file_put_contents($fileFullPath, $this->content);
- return true;
- }
- return false;
- }
- public function show()
- {
- if (empty($this->content)) {
- $this->getScreenShot();
- }
- echo '*' . $this->content . '*';
- }
- }
- ScreenShot::make('test', 'https://www.youtube.com/', 2560)->show();
File Description
- acdsc
- PHP Code
- 15 Dec-2018
- 2.23 Kb
You can Share it:
Latest PHP Pastes