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);
return $new_name;
}
}
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)
imageResize($_FILES['image']['tmp_name'], 700);
$file_tmp = $_FILES['image']['tmp_name'];
move_uploaded_file($file_tmp,"../images/".$file_name);
echo 'Успешно добавлено!';
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['image']['tmp_name']);
return $_FILES['image']['tmp_name'];
imagedestroy($thumb);
}
<?php
function upload_image()
{
if(isset($_FILES['user_image']))
{
$extension = explode('.', $_FILES['user_image']['name']);
$new_name = rand() . '.' . $extension[1];
$destination = '../reviews/upload/' . $new_name;
imageResize($_FILES['user_image']['tmp_name'], 700);
$file_tmp = $_FILES['user_image']['tmp_name'];
move_uploaded_file($file_tmp, $destination);
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['image']['tmp_name']);
return $_FILES['image']['tmp_name'];
imagedestroy($thumb);
}
выдает ошибку и загружает только один вариант картинки без ресайза
<?php
function upload_image()
{
if(isset($_FILES['user_image']))
{
$extension = explode('.', $_FILES['user_image']['name']);
$new_name = rand() . '.' . $extension[1];
$destination = '../reviews/upload/' . $new_name;
imageResize($_FILES['user_image']['tmp_name'], 700);
$file_tmp = $_FILES['user_image']['tmp_name'];
move_uploaded_file($file_tmp, $destination);
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);
}
а нужно чтобы изо которые после обрезки загружались в папку thumb, а полноразмерные просто в upload
<?php
function upload_image()
{
if(isset($_FILES['user_image']))
{
$extension = explode('.', $_FILES['user_image']['name']);
$new_name = rand() . '.' . $extension[1];
$destination = '../reviews/upload/' . $new_name;
$thimbDestination = '../reviews/thumb/' . $new_name;
move_uploaded_file($file_tmp, $destination);
imageResize($_FILES['user_image']['tmp_name'], 700);
$file_tmp = $_FILES['user_image']['tmp_name'];
move_uploaded_file($file_tmp, $thumbDestination);
return $new_name;
}
}
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);
}
и почему если я меняю цифру 700, то картинка больше не маштабируется?- а исходная какая?
copy($folder . '1.jpg', $folder . '2.jpg');
<?php
function upload_image()
{
if(isset($_FILES['user_image']))
{
$extension = explode('.', $_FILES['user_image']['name']);
$new_name = rand() . '.' . $extension[1];
$destination = '../reviews/upload/' . $new_name;
$thimbDestination = '../reviews/thumb/' . $new_name;
move_uploaded_file($file_tmp, $destination);
$thumb = imageResize($destination, 700);
copy($thumb, $thumbDestination);
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, $new_thumb);
return $new_thumb;
imagedestroy($thumb);
}
function upload_image()
{
if(isset($_FILES['user_image']))
{
$extension = explode('.', $_FILES['user_image']['name']);
$new_name = rand() . '.' . $extension[1];
$destination = '../reviews/upload/' . $new_name;
$thimbDestination = '../reviews/upload/thumb/';
move_uploaded_file($file_tmp, $destination);
$thumb = imageResize($destination, 300);
copy($thumb, $thimbDestination);
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, $new_thumb);
return $new_thumb;
imagedestroy($thumb);
}
function upload_image()
{
if(isset($_FILES['user_image']))
{
$extension = explode('.', $_FILES['user_image']['name']);
$new_name = rand() . '.' . $extension[1];
$destination = '../reviews/upload/' . $new_name;
$thimbDestination = '../reviews/upload/thumb/';
move_uploaded_file($_FILES['user_image']['tmp_name'], $destination);
$thumb = imageResize($destination, 300);
copy($thumb, $thimbDestination);
return $new_name;
}
}
$thumb = imageResize($destination, 300);
copy($thumb, $thimbDestination);
function upload_image()
{
if(isset($_FILES['user_image']))
{
$extension = explode('.', $_FILES['user_image']['name']);
$new_name = rand() . '.' . $extension[1];
$destination = '../reviews/upload/' . $new_name;
$thimbDestination = '../reviews/upload/thumb/' . $new_name;
move_uploaded_file($_FILES['user_image']['tmp_name'], $destination);
var_dump($thumb = imageResize($destination, 300));
copy($thumb, $thimbDestination);
return var_dump;
}
}
function upload_image()
{
if(isset($_FILES['user_image']))
{
$extension = explode('.', $_FILES['user_image']['name']);
$new_name = rand() . '.' . $extension[1];
$destination = '../reviews/upload/' . $new_name;
$thimbDestination = '../reviews/upload/thumb/';
move_uploaded_file($file_tmp, $destination);
$v = var_dump(imageResize($destination, 300));
return $v;
}
}
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, $new_thumb);
return $new_thumb;
imagedestroy($thumb);
}
function upload_image()
{
if(isset($_FILES['user_image']))
{
$extension = explode('.', $_FILES['user_image']['name']);
$new_name = rand() . '.' . $extension[1];
$destination = '../reviews/upload/' . $new_name;
$thimbDestination = '../reviews/upload/thumb/' . $new_name;
move_uploaded_file($_FILES['user_image']['tmp_name'], $destination);
$v = var_dump(imageResize($destination, 300));
return $v;
}
}
<?php
function upload_image()
{
if(isset($_FILES['userfile']))
{
$extension = explode('.', $_FILES['userfile']['name']);
$new_name = rand() . '.' . $extension[1];
$destination = '../' . $new_name;
$thimbDestination = '../TEST/' . $new_name;
move_uploaded_file($_FILES['userfile']['tmp_name'], $destination);
imageResize($destination, 500);
$file_tmp = $_FILES['userfile']['tmp_name'];
copy($file_tmp, $thimbDestination);
return $thimbDestination;
}
}
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['userfile']['tmp_name']);
return $_FILES['userfile']['tmp_name'];
imagedestroy($thumb);
}
?>
<html>
<div style="width:800px; margin:auto; padding-top:100px;">
<?php
var_dump(upload_image());
?>
<hr>
<form action="" method="post" enctype="multipart/form-data">
Файлы:
<br/><br/>
<input name="userfile" type="file" multiple/><br /><br />
<input type="submit" value="Отправить" />
</form></div>
</html>