<?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>
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);
}
<?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);
}