Начало работы - поправил форму, начал делать обработчик
This commit is contained in:
parent
27e4f6d577
commit
f653347ba8
|
|
@ -0,0 +1,107 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class Image
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param string $path
|
||||||
|
* @return mix string-base64 or false
|
||||||
|
*/
|
||||||
|
public static function toBase64($path)
|
||||||
|
{
|
||||||
|
if ($path)
|
||||||
|
{
|
||||||
|
$type = pathinfo($path, PATHINFO_EXTENSION);
|
||||||
|
|
||||||
|
if (!$type)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = file_get_contents($path);
|
||||||
|
|
||||||
|
return $data ? 'data:image/' . $type . ';base64,' . base64_encode($data) : FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ресайзит изображение. На входе запрос вида sizeX_sizeY_imgName.ext
|
||||||
|
* @param type $name
|
||||||
|
*/
|
||||||
|
public static function resize($imgName, $sizeX, $sizeY = false, $quality = 85)
|
||||||
|
{
|
||||||
|
$dir = 'photos/';
|
||||||
|
$newDir = 'photos/resize/';
|
||||||
|
|
||||||
|
$sizeY = $sizeY ? $sizeY : $sizeX;
|
||||||
|
|
||||||
|
|
||||||
|
$oldImgName = $dir . $imgName;
|
||||||
|
$newImgName = $newDir . $sizeX . '_' . $sizeY . '_' . $imgName;
|
||||||
|
|
||||||
|
if (file_exists($newImgName) || self::imgResize($oldImgName, $newImgName, $sizeX, $sizeY, $quality))
|
||||||
|
{
|
||||||
|
return '/' . $newImgName;
|
||||||
|
}
|
||||||
|
|
||||||
|
return '/' . $oldImgName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Функция img_resize(): генерация thumbnails
|
||||||
|
* Параметры:
|
||||||
|
* $src - имя исходного файла
|
||||||
|
* $dest - имя генерируемого файла
|
||||||
|
* $width, $height - ширина и высота генерируемого изображения, в пикселях
|
||||||
|
* Необязательные параметры:
|
||||||
|
* $quality - качество генерируемого JPEG, по умолчанию 90; максимальное 100;
|
||||||
|
*/
|
||||||
|
private static function imgResize($src, $dest, $width, $height, $quality = 90)
|
||||||
|
{
|
||||||
|
if (!file_exists($src))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
$size = getimagesize($src);
|
||||||
|
|
||||||
|
if ($size === false)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Определяем исходный формат по MIME-информации, предоставленной
|
||||||
|
// функцией getimagesize, и выбираем соответствующую формату
|
||||||
|
// imagecreatefrom-функцию.
|
||||||
|
$format = strtolower(substr($size['mime'], strpos($size['mime'], '/') + 1));
|
||||||
|
$icfunc = "imagecreatefrom" . $format;
|
||||||
|
if (!function_exists($icfunc))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
$x_ratio = $width / $size[0];
|
||||||
|
$y_ratio = $height / $size[1];
|
||||||
|
|
||||||
|
$ratio = max($x_ratio, $y_ratio);
|
||||||
|
$use_x_ratio = ($x_ratio == $ratio);
|
||||||
|
|
||||||
|
$new_width = $use_x_ratio ? $width : floor($size[0] * $ratio);
|
||||||
|
$new_height = !$use_x_ratio ? $height : floor($size[1] * $ratio);
|
||||||
|
$new_left = $use_x_ratio ? 0 : floor(($width - $new_width) / 2);
|
||||||
|
$new_top = !$use_x_ratio ? 0 : floor(($height - $new_height) / 2);
|
||||||
|
|
||||||
|
$isrc = $icfunc($src);
|
||||||
|
$idest = imagecreatetruecolor($width, $height);
|
||||||
|
|
||||||
|
imagefill($idest, 0, 0, 0xFFFFFF);
|
||||||
|
imagecopyresampled($idest, $isrc, $new_left, $new_top, 0, 0, $new_width, $new_height, $size[0], $size[1]);
|
||||||
|
|
||||||
|
//$iofunct = "image".$format;
|
||||||
|
//$iofunct($idest, $dest, $quality);
|
||||||
|
imagejpeg($idest, $dest, $quality);
|
||||||
|
|
||||||
|
imagedestroy($isrc);
|
||||||
|
imagedestroy($idest);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -8,6 +8,12 @@ return array(
|
||||||
'password' => 'root',
|
'password' => 'root',
|
||||||
'dbname' => 'poi',
|
'dbname' => 'poi',
|
||||||
),
|
),
|
||||||
//'version' => trim(file_get_contents(dirname(__FILE__).'/version')),
|
'images' => array(
|
||||||
|
// 'dirName' => array(maxX, maxY, quality),
|
||||||
|
'small' => array(200, 150, 100),
|
||||||
|
'middle' => array(555, 450, 90),
|
||||||
|
'big' => array(1110, 900, 90),
|
||||||
|
),
|
||||||
|
//'version' => trim(file_get_contents(dirname(__FILE__).'/version')),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,29 @@ class JsonController extends Controller
|
||||||
*/
|
*/
|
||||||
static function actionAddPoint()
|
static function actionAddPoint()
|
||||||
{
|
{
|
||||||
$errors = array();
|
$photos = array();
|
||||||
|
$temp = pathinfo($_SERVER['SCRIPT_FILENAME']);
|
||||||
|
$uploaddir = $temp['dirname'] . '/photos/';
|
||||||
|
// print_r($_FILES);
|
||||||
|
// print_r($_REQUEST);
|
||||||
|
// die;
|
||||||
|
if (isset($_FILES) && !empty($_FILES))
|
||||||
|
{
|
||||||
|
foreach ($_FILES['photos']['name'] as $key => $fileName)
|
||||||
|
{
|
||||||
|
$temp = pathinfo($_FILES['photos']['name'][$key]);
|
||||||
|
|
||||||
|
$foto = strtolower('_' . substr(md5($fileName . time()), 0, 5) . '.' . $temp['extension']);
|
||||||
|
if (move_uploaded_file($_FILES['photos']['tmp_name'][$key], $uploaddir . $foto))
|
||||||
|
{
|
||||||
|
$photos[] = $foto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print_r($photos);
|
||||||
|
die;
|
||||||
|
|
||||||
|
$errors = array();
|
||||||
|
|
||||||
if(!( isset($_POST['name']) && $_POST['name'] && strlen($_POST['name']) > 1 )) $errors[1]='Неверное название точки';
|
if(!( isset($_POST['name']) && $_POST['name'] && strlen($_POST['name']) > 1 )) $errors[1]='Неверное название точки';
|
||||||
if(!( isset($_POST['img']) && $_POST['img'] && strlen($_POST['img']) > 13 )) $errors[2]='Плохая ссылка на изображение';
|
if(!( isset($_POST['img']) && $_POST['img'] && strlen($_POST['img']) > 13 )) $errors[2]='Плохая ссылка на изображение';
|
||||||
|
|
|
||||||
|
|
@ -6,29 +6,35 @@
|
||||||
<h4 class="modal-title" id="myModalLabel">Добавление новой точки</h4>
|
<h4 class="modal-title" id="myModalLabel">Добавление новой точки</h4>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body" style="padding-bottom: 0;">
|
<div class="modal-body" style="padding-bottom: 0;">
|
||||||
<form method="POST" action="/json/addpoint/" id="addPointForm">
|
<form method="POST" action="/json/addpoint/" id="addPointForm" enctype="multipart/form-data">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="control-label" for="name">Название</label>
|
<label class="control-label" for="name">Название</label>
|
||||||
<label class="control-label error" for="name">(Слишком короткое название точки)</label>
|
<label class="control-label error" for="name">(Слишком короткое название точки)</label>
|
||||||
<input type="text" id="addPointName" name="name" class="form-control" />
|
<input type="text" id="addPointName" name="name" class="form-control" />
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
|
||||||
<label class="control-label" for="img">URL изображения (по ссылке должна открываться фотография)</label>
|
|
||||||
<label class="control-label error" for="img">(Что-то не так с сылкой на изображение)</label>
|
|
||||||
<input type="text" id="addPointImg" name="img" class="form-control" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="control-label" for="description">Описание</label>
|
<label class="control-label" for="description">Описание</label>
|
||||||
<label class="control-label error" for="img">(Слишком короткое описание - минимум 25 символов)</label>
|
<label class="control-label error" for="description">(Слишком короткое описание - минимум 25 символов)</label>
|
||||||
<textarea id="addPointDescription" name="description" class="form-control"></textarea>
|
<textarea id="addPointDescription" name="description" class="form-control" rows="4"></textarea>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group extraImage asLink">
|
||||||
|
<label class="control-label" for="img">Файлы и ссылки (URL) на изображения</label>
|
||||||
|
<label class="control-label error" for="img">(Что-то не так с сылкой на изображение)</label>
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-addon type ico" title="Укажите ссылку на изображение"><span class="glyphicon glyphicon-link"></span></div>
|
||||||
|
<input type="text" id="" name="imgs[]" class="form-control" placeholder="http://" />
|
||||||
|
<div class="input-group-addon type button" onclick="switchType($(this))" title="Загрузить файл"><span class="glyphicon glyphicon-transfer"></span></div>
|
||||||
|
<div class="input-group-addon add button" onclick="addNewImage()" title="Добавить ещё одно изображение"><span class="glyphicon glyphicon-plus"></span></div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="control-label" for="categoryId">Тип</label>
|
<label class="control-label" for="categoryId">Тип</label>
|
||||||
<select id="addPointCategoryId" name="categoryId" class="form-control">
|
<select id="addPointCategoryId" name="categoryId" class="form-control">
|
||||||
<?php foreach ($categories as $category): ?>
|
<?php foreach ($categories as $category): ?>
|
||||||
<option value="<?=$category['id']?>"><?=$category['name']?></option>
|
<option value="<?=$category->id?>"><?=$category->name?></option>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -40,16 +46,61 @@
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
Координаты:
|
Координаты:
|
||||||
<input type="text" id="addPointLat" name="lat" class="form-control input-sm" style="width: 120px; display: inline-block;" readonly="readonly" disabled="disabled"/>
|
<input type="text" id="addPointLat" name="lat" class="form-control input-sm" style="width: 145px; display: inline-block;" readonly="readonly" disabled="disabled"/>
|
||||||
<input type="text" id="addPointLng" name="lng" class="form-control input-sm" style="width: 120px; display: inline-block;" readonly="readonly" disabled="disabled"/>
|
<input type="text" id="addPointLng" name="lng" class="form-control input-sm" style="width: 145px; display: inline-block;" readonly="readonly" disabled="disabled"/>
|
||||||
<button type="button" class="btn btn-sm btn-default" onclick="editSetNewCoords();"><span class="glyphicon glyphicon-flag"></span></button>
|
<button type="button" class="btn btn-sm btn-default" onclick="editSetNewCoords();"><span class="glyphicon glyphicon-screenshot"></span> изменить координаты</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-default" data-dismiss="modal">Отмена</button>
|
<button type="button" class="btn btn-default" data-dismiss="modal">Отмена</button>
|
||||||
<button type="button" class="btn btn-primary" onclick="addPoint();">Сохранить</button>
|
<button type="button" class="btn btn-primary" onclick="$('#addPointForm').submit();">Сохранить</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="newIm">
|
||||||
|
<div class="form-group extraImage asLink" style="display: none;">
|
||||||
|
<label class="control-label error" for="img">(Что-то не так с сылкой на изображение)</label>
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-addon type ico" title="Укажите ссылку на изображение"><span class="glyphicon glyphicon-link"></span></div>
|
||||||
|
<input type="text" name="imgs[]" class="form-control" />
|
||||||
|
<div class="input-group-addon type button" onclick="switchType($(this))" title="Изменить поле на загрузку файла"><span class="glyphicon glyphicon-transfer"></span></div>
|
||||||
|
<div class="input-group-addon remove button" onclick="removeInput($(this))" title="Удалить это поле"><span class="glyphicon glyphicon-trash"></span></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<script>
|
||||||
|
function addNewImage()
|
||||||
|
{
|
||||||
|
if ($('.extraImage', '#addPointForm').length < 10)
|
||||||
|
$('.extraImage', '#newIm').clone().insertAfter($('.extraImage', '#addPointForm').last()).show(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeInput(el)
|
||||||
|
{
|
||||||
|
$(el).parent().parent().hide(300, function(){$(el).remove()});
|
||||||
|
}
|
||||||
|
|
||||||
|
function switchType(el)
|
||||||
|
{
|
||||||
|
container = $(el).parent().parent();
|
||||||
|
if (container.hasClass('asLink'))
|
||||||
|
{
|
||||||
|
$('.ico span', container).removeClass('glyphicon-link').addClass('glyphicon-paperclip');
|
||||||
|
$('.form-control', container).attr('type', 'file').attr('name', 'photos[]');
|
||||||
|
container.removeClass('asLink');
|
||||||
|
el.attr('title', 'Указать ссылку на изображение');
|
||||||
|
$('.input-group-addon.type.ico', container).attr('title', 'Загрузите файл с изображением');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$('.ico span', container).removeClass('glyphicon-paperclip').addClass('glyphicon-link');
|
||||||
|
$('.form-control', container).attr('type', 'text').attr('name', 'imgs[]');
|
||||||
|
container.addClass('asLink');
|
||||||
|
el.attr('title', 'Загрузить файл');
|
||||||
|
$('.input-group-addon.type.ico', container).attr('title', 'Укажите ссылку на изображение');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,11 @@ div.header a:hover {text-decoration: none;}
|
||||||
div.header a:hover h1 {cursor: pointer;}
|
div.header a:hover h1 {cursor: pointer;}
|
||||||
div.add {cursor: pointer;}
|
div.add {cursor: pointer;}
|
||||||
|
|
||||||
|
#addPointModal .extraImage .button {cursor: pointer;}
|
||||||
|
#addPointModal .extraImage .remove:hover {background-color: #d44950; color: #fff;}
|
||||||
|
#addPointModal .extraImage .add:hover {background-color: #49d450; color: #fff;}
|
||||||
|
#addPointModal .extraImage .type.button:hover {background-color: #ddd;}
|
||||||
|
|
||||||
.form-group .error {display: none;}
|
.form-group .error {display: none;}
|
||||||
.form-group.has-error .error {display: inline-block;}
|
.form-group.has-error .error {display: inline-block;}
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 238 KiB |
Loading…
Reference in New Issue