function upload_image_array()
{
$res = array();
if(isset($_FILES['user_image']))
{
// Count total files
$countfiles = count($_FILES['user_image']['name']);
for($i=0;$i<$countfiles;$i++){
$extension = explode('.', $_FILES['user_image']['name'][$i]);
$new_name = rand() . '.' . $extension[1];
$destination = '../portfolio/upload/' . $new_name;
$thumbDestination = '../portfolio/upload/thumb/' . $new_name;
move_uploaded_file($_FILES['user_image']['tmp_name'][$i], $destination);
resize($destination, $thumbDestination, 300);
$res[] = $new_name;
}
return $res;
}
}
if($_POST["operation"] == "Add")
{
$images = array();
if($_FILES["user_image"]["name"] != '')
{
$images = upload_image_array();
}
foreach ($images as $image){
$statement = $connection->prepare("
INSERT INTO portfolio (image, image_mini)
VALUES (:image, :image_mini)
");
$result = $statement->execute(
array(
':image' => $image,
':image_mini' => $image
)
);
}
if(!empty($result))
{
echo 'Фото Добавлено';
}
}
$rows[] = [
'username' => 'bob',
'email' => 'bob@example.com'
];
$rows = [];
$rows[] = [
'username' => 'bob',
'email' => 'bob@example.com'
];
$rows[] = [
'username' => 'max',
'email' => 'max@example.com'
];
$sql = "INSERT INTO users SET username=:username, email=:email;";
$stmt = $pdo->prepare($sql);
foreach ($rows as $row) {
$stmt->execute($row);
}
if($_POST["operation"] == "Add")
{
$image = '';
if($_FILES["user_image"]["name"] != '')
{
$image = upload_image();
}
$statement = $connection->prepare("
INSERT INTO portfolio (image, image_mini)
VALUES (:image, :image_mini)
");
$result = $statement->execute(
array(
':image' => $image,
':image_mini' => $image
)
);
if(!empty($result))
{
echo 'Фото Добавлено';
}
}
$result = $statement->execute(
array(
':image' => $image,
':image_mini' => $image
)
);
if($_POST["operation"] == "Add")
{
$image = '';
if($_FILES["user_image"]["name"] != '')
{
$image = upload_image();
}
$statement = $connection->prepare("
INSERT INTO portfolio (image, image_mini)
VALUES (:image, :image_mini)
");
$result = $statement->execute(
array(
':image' => $image,
':image_mini' => $image
)
);
if(!empty($result))
{
echo 'Фото Добавлено';
}
}
<form method="post" id="user_form" enctype="multipart/form-data">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Добавление фото</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<label>Выбрать фото:</label>
<br />
<div class="row">
<div class="col my-auto">
<input type="file" name="user_image[]" id="user_image" multiple/>
</div>
<div class="col my-auto">
<span id="user_uploaded_image"></span>
</div>
</div>
</div>
<div class="modal-footer">
<input type="hidden" name="user_id" id="user_id" />
<input type="hidden" name="operation" id="operation" />
<input type="submit" name="action" id="action" class="btn btn-success" value="Добавить" />
<button type="button" class="btn btn-danger" data-dismiss="modal">Закрыть</button>
</div>
</div>
</form>
function upload_image()
{
if(isset($_FILES['user_image']))
{
// Count total files
$countfiles = count($_FILES['user_image']['name']);
for($i=0;$i<$countfiles;$i++){
$extension = explode('.', $_FILES['user_image']['name'][$i]);
$new_name = rand() . '.' . $extension[1];
$destination = '../portfolio/upload/' . $new_name;
$thimbDestination = '../portfolio/upload/thumb/' . $new_name;
move_uploaded_file($_FILES['user_image']['tmp_name'][$i], $destination);
imageResize($destination, 300);
$file_tmp = $_FILES['user_image']['tmp_name'][$i];
copy($file_tmp, $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, $_FILES['user_image']['tmp_name']);
return $_FILES['user_image']['tmp_name'];
imagedestroy($thumb);
}
imageResize($destination, 300);
$file_tmp = $_FILES['user_image']['tmp_name'][$i];
copy($file_tmp, $thimbDestination);
У тебя есть телега или Вайбер или ватсап?
Будем связь держать))