PHP:
скопировать код в буфер обмена
скопировать код в буфер обмена
- <?PHP
- Class Upload extends SimpleImage
- {
- private $text;
- private $filename;
- private $filesize;
- private $filetmp;
- private $link;
- private $thumb_link;
- private $err;
- public $valid_extensions;
- public function __construct($text, $name, $size, $tmp)
- {
- /**
- * file data array
- */
- $this->text = $text;
- $this->filename = $name;
- $this->filesize = $size;
- $this->filetmp = $tmp;
- $this->valid_extensions = $valid_extensions;
- /**
- * Clean text
- */
- if($this->filesize == 0)
- {
- $this->err[] = display_msg("Ошибка", "alert-error", "Файл не выбран");
- }
- /**
- * get ext file
- */
- /**
- * unick name for image
- */
- {
- $allowed = 0;
- foreach ($valid_extensions as $ext)
- {
- $allowed = 1;
- }
- if ($allowed == 0)
- {
- $this->err[] = display_msg('Ошибка', 'alert-error', 'Неверный формат изображения');
- }
- }
- /**
- * path for upload and write table
- */
- $this->link = UPLOAD_DIR . $this->new_img_name;
- $this->link_thumb = UPLOAD_DIR_THUMB . $this->new_img_name;
- if($this->Check_Image($this->filetmp, $valid_extensions))
- {
- $this->err[] = 'Это не картинка';
- }
- /**
- * default value for text
- */
- {
- $this->text = '<span class="label label-success"> Подписи нет </span>';
- }
- /**
- * Echo error msg
- */
- $this->Error_Count1();
- /**
- * start upload and insert data
- */
- $this->Uploading();
- }
- /**
- * anti-upload for other files
- */
- private function Check_Image()
- {
- if(!$image_info = get_image_info($this->filetmp) or !in_array($image_info['extension'], $this->valid_extensions))
- {
- return false;
- }
- }
- /**
- * function uploading file and insert data to table
- */
- private function Uploading()
- {
- /**
- * start upload
- */
- {
- /**
- * get size images
- */
- /**
- * if width > thumbnail size
- */
- if($width > MAX_FILE_SIZE)
- {
- $this->load($this->link);
- $this->resizeToHeight(MAX_FILE_SIZE);
- $this->save($this->link_thumb);
- }
- else
- {
- $this->link_thumb = $this->link;
- }
- /**
- * if image very small
- */
- if($width < MIN_SIZE_FILE || $height < MIN_SIZE_FILE)
- {
- $this->err[] = display_msg('Ошибка', 'alert-error', 'Пикча маловата');
- }
- /**
- * check errors and msg
- */
- $this->Error_Count1();
- /**
- * connect db
- */
- db::connect(HOST, USER, PASSWD, DB);
- db::setCharset(CHARSET);
- /**
- * insert data to table
- */
- db::set("INSERT INTO post (
- id_post,
- text_post,
- img_large,
- img_mini,
- date_post
- ) VALUES (
- '%s',
- '%s',
- '%s',
- '%s',
- NOW()
- )",
- NULL, $this->text, $this->link, $this->link_thumb
- );
- /**
- * Good upload
- */
- $this->err[] = display_msg('Сообщение', 'alert-info', 'Сообщение добавлено на проверку');
- }
- else
- {
- /**
- * truble upload
- */
- $this->err[] = display_msg('Ошибка', 'alert-error', 'При загрузке возникли какие-то неполадки');
- }
- /**
- * echo msg or error
- */
- $this->Error_Count1();
- exit;
- }
- /**
- * function count and return errors and msg
- */
- private function Error_Count1()
- {
- {
- foreach($this->err as $display_error)
- {
- $this->error_dis = $display_error;
- echo $this->error_dis;
- exit;
- }
- }
- }
- }