JavaScript
0
Вклад в тег
<form method="POST" enctype="multipart/form-data">
<div class="image-editor">
<input name="imgs" type="file" class="cropit-image-input">
<div class="cropit-image-preview"></div>
<div class="image-size-label">
Resize image
</div>
<input type="range" class="cropit-image-zoom-input">
<input type="hidden" name="img" class="hidden-image-data">
</div>
<input type="submit" id="submit" value="Отправить">
</form>
<script>
$(function() {
$('.image-editor').cropit();
$('.image-editor').cropit('previewSize', { width: 500, height: 750 });
$('form').submit(function(e) {
e.preventDefault();
var imageData = $('.image-editor').cropit('export',{
type: 'image/jpeg',
quality: .6
});
var hidden = $('.hidden-image-data').val(imageData);
var form = $('form');
var formData = new FormData(form[0]);
$.ajax({
type: "POST",
processData: false,
contentType: false,
url: "php/addPP.php",
data: formData,
success: function(data){
alert(data);
}
})
});
});
</script>
<?
session_start();
include("db.php");
$img = $_POST['img'];
$img = str_replace('data:image/jpeg;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$year = time();
$img = file_put_contents('../img/'.$year.'.jpg', base64_decode($img));
$result = mysqli_query ($link, "INSERT INTO test (img) VALUES ('$year');");
echo $result;