HTML KODU



<div class="form-group row">
<label for="images" class="col-sm-12 col-md-2 col-form-label">Resimler (Maks. 6)</label>
<div class="col-sm-12 col-md-10">
<input type="file" id="images" name="images[]" multiple required>
</div>
</div>


PHP İŞLEM KODU


<?php
if (isset($_FILES['images']) && count($_FILES['images']['name']) <= 6) {
$uploadDir = __DIR__ . '/../resim/';
$fileNames = [];
$uploadError = false;

// Her dosya için döngü
for ($i = 0; $i < count($_FILES['images']['name']); $i++) {
if ($_FILES['images']['error'][$i] === UPLOAD_ERR_OK) {
$fileTmpPath = $_FILES['images']['tmp_name'][$i];
$fileName = $_FILES['images']['name'][$i];
$fileNameCmps = explode('.', $fileName);
$fileExtension = strtolower(end($fileNameCmps));

$allowedExts = ['jpg', 'jpeg', 'png', 'gif'];
if (in_array($fileExtension, $allowedExts)) {
// Benzersiz dosya adı oluşturma
$uniqueID = uniqid('', true);
$newFileName = $uniqueID . '.' . $fileExtension;
$destPath = $uploadDir . $newFileName;

// Dosyayı yükle ve filigran ekle
if (move_uploaded_file($fileTmpPath, $destPath)) {
addWatermark($destPath, $uniqueID);
$fileNames[] = $newFileName;
} else {
$uploadError = true;
error_log("Dosya yükleme hatası: $fileName");
break;
}
} else {
$uploadError = true;
error_log("Geçersiz dosya uzantısı: $fileExtension");
break;
}
} else {
$uploadError = true;
error_log("Dosya yükleme hatası: " . $_FILES['images']['error'][$i]);
break;
}
}

// Dosya yükleme başarılı mı?
if (!$uploadError) {
echo "Dosyalar başarıyla yüklendi: ";
foreach ($fileNames as $name) {
echo $name . "<br>";
}
} else {
echo "Dosya yükleme sırasında bir hata oluştu.";
}
} else {
echo "Lütfen en fazla 6 dosya seçin.";
}
?>