function upload_image()
{
if(isset($_FILES['user_image']))
{
$extension = explode('.', $_FILES['user_image']['name']);
$new_name = rand() . '.' . $extension[1];
$destination = '../reviews/upload/' . $new_name;
move_uploaded_file($_FILES['user_image']['tmp_name'], $destination);
imageResize($_FILES['user_image']['tmp_name'], 300);
$file_tmp = $_FILES['user_image']['tmp_name'];
$destination_thumb = '../reviews/upload/thumb';
move_uploaded_file($file_tmp, $destination_thumb);
return $new_name;
}
}
function imageResize($file_path, $new_width){
//Получаем ширину и высоту исходника
list($w, $h) = getimagesize($file_path);
//Получаем коэфицент соотношения сторон
$proportions = $h / $w;
$new_w = $new_width;
$new_h = $new_w * $proportions; // Получаем высоту уменьшенной картинки пропорционально новой ширине
$thumb = imagecreatetruecolor($new_w, $new_h);
$source = imagecreatefromjpeg($file_path);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $new_w, $new_h, $w, $h);
imagejpeg($thumb, $_FILES['user_image']['tmp_name']);
return $_FILES['user_image']['tmp_name'];
imagedestroy($thumb);
}
var description_en = $('#description_en').val();
var extension = $('#user_image').val().split('.').pop().toLowerCase();
if(extension != '')
{
if(jQuery.inArray(extension, ['gif','png','jpg','jpeg']) == -1)
<div class="gallery">
<?php
include_once 'includes/db_connect.php';
$query = $db->query("SELECT * FROM portfolio ORDER BY id DESC LIMIT 15");
while($row = $query->fetch_assoc()):
$imageURL = 'img/portfolio/'.$row["file_name"];
$imageId = $row["id"];
?>
<div class="gallery_block">
<a class="views" href="<?php echo $imageURL; ?>">
<img data-image-id=<?= $imageId ?> src="<?php echo $imageURL; ?>" />
</a>
</div>
<?php endwhile; ?>
</div>
$('.views').click(function() {
var id = $(this).attr('data-image-id');
$.ajax({
type: 'POST',
url: 'includes/ajax.php',
data : {id: id},
});
return false;
});
<?php
include 'db_connect.php';
$id = $_POST['id'];
mysqli_query($db, "UPDATE portfolio SET views = views + 1 WHERE id = '$id'");
?>
<?php
include 'db_connect.php';
$id = $_POST['id'];
mysqli_query($db, "UPDATE portfolio SET views = views + 1 WHERE id = $id");
?>
<?php
include 'db_connect.php';
$imageURL = 'img/portfolio/'.$row["file_name"];
mysqli_query($db, "UPDATE portfolio SET views = views + 1 WHERE id");
?>
<?php
include 'db_connect.php';
mysqli_query($db, "UPDATE portfolio SET views = views + 1");
?>
move_uploaded_file($file_tmp, $destination);