Hi guys Im trying to save multiples images with php, and I did it, but when I save the link on the Database, if I upload 3 images, its show 2 empty links with the raname name I had created, i would like when users upload 3 images its generate Just the 3 url of the images he/she upload, also I would like to save the first image on a diferent var ($foto), im will appreciate any hepl from you! thank you so much
this is my code HTML:
<form enctype="multipart/form-data" action="recursos/form_process.php" method="POST">
<div id="text">
<div>
<input name="data[]" id="file" type="file" multiple="multiple" />
</div>
</div>
<input type="button" id="add-file-field" name="add" value="Agregar otra foto" />
<input type='hidden' name="action" value="uploadfiles" />
<input type="submit" class="formsubmit" value="Subir y terminar" />
</form>
PHP
<?php
session_start();
include('conexion.php');
if(isset($_POST['action'])=='uploadfiles')
{
//Rename variables
$time = time();
$random = substr(number_format(time() * rand(),0,'',''),0,10);
$seed = str_split('AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789' );
shuffle($seed);
$rand = '' ;
foreach (array_rand($seed, 10) as $k) $rand .= $seed[$k];
//NEW NAME CODE
$new_name = "$rand" . "$random" . "$time";
$upload_directory = '../uploads/';
$count_data = count($_FILES['data']) ;
$upload = $_FILES['data']['name'][$x].',';
for($x=0;$x<$count_data;$x++) {
$upload .= $new_name . $_FILES['data']['name']["$x" . ""].','; ##### column Name you can use comma in ending use to stored like this for ex: first.jpg,second.jpg,third.png like this it will stored into database #######
move_uploaded_file($_FILES['data']['tmp_name'][$x], $upload_directory . $new_name . $_FILES['data']['name'][$x]);
}
$con = "INSERT INTO provicional (fotos) values ('$upload')";
$query = mysql_query($con);
}
?>