I'm a beginner in PHP and I'm developing a system for real estate. The annoying thing that occurred to me was this: I need to upload 20 photos of a property using only 1 input and save the file name in the bank. I can upload the files and resize them perfectly, however I'm having trouble saving the name of each image separately in the table. For example, I can interpret the image and rename it but the first image should be in the "photo1" column while the second in the "photo2" column, but I did not find a function to interpret each file separately, so all the columns receive the value only of the the last file selected in the multiple input.
Reduced version of the code:
<html>
<body>
<form action="#" method="POST" enctype="multipart/form-data">
<input type="file" name="fileUpload[]" multiple>
<input type="submit" value="Enviar">
</form>
</body>
</html>
<?php
if(isset($_FILES['fileUpload']))
{
require 'WideImage/WideImage.php';
date_default_timezone_set("Brazil/East");
$name = $_FILES['fileUpload']['name'];
$tmp_name = $_FILES['fileUpload']['tmp_name'];
$allowedExts = array(".gif", ".jpeg", ".jpg", ".png", ".bmp");
$dir = 'uploads/';
for($i = 0; $i < count($tmp_name); $i++)
{
$ext = strtolower(substr($name[$i],-4));
if(in_array($ext, $allowedExts))
{
$new_name = date("Y.m.d-H.i.s") ."-". $i . $ext;
$image = WideImage::load($tmp_name[$i]);
$image = $image->resize(170, 180, 'outside');
$image = $image->crop('center', 'center', 170, 180);
$image->saveToFile($dir.$new_name);
$sql = "INSERT INTO imoveis (foto1) VALUES ('$new_name')";
$result = mysql_query($sql) or die('Erro ao executar instrucao SQL :-( ERRO->'.mysql_error());
}
}
}
?>