Тема: Простой класс для работы с API / Code Igniter
Сам класс
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Sshot {
public $url = null;
public $path = null;
public $filename = null;
public $resolution = '1024x768';
public $size = '400';
public $format = 'jpeg';
/**
* Constructor
*
* @access public
* @param array initialization parameters
*/
public function __construct($params) {
foreach ($params as $key => $value) {
$this->$key = $value;
}
}
function get_shot() {
if ($this->url && $this->path && $this->filename) {
$full_filename = $this->path.$this->filename.'.'.$this->format;
$copy_url = 'http://mini.s-shot.ru/'.$this->resolution.'/'.$this->size.'/'.$this->format.'/?'.$this->url;
if (copy($copy_url, $full_filename)) {
$success = true;
$response = array('filename' => $this->filename.'.'.$this->format, 'format' => $this->format);
}
else {
$success = false;
$response = 'Error: copy failed.';
}
}
else {
$success = false;
$response = 'Error: path or url.';
}
return (object) array('success' => $success, 'response' => $response);
}
}
/* End of file Sshot.php */
Использование:
$config['url'] = 'http://otsledit.com/ru';
$config['path'] = '/home/';
$this->load->library('sshot', $config);
$shot = $this->sshot->get_shot();
var_dump($shot);