I'm trying to get the value of an array but I can't. I've got this page to upload a variable number of photos and their relative descriptions (to be stored in a DB)
for ($i=1; $i<$val; $i++)
{
echo '<div class="row">';
echo '<div class="col-xl-4 col-lg-4 col-md-6 mt-2">';
echo '<div class="file-field" style="margin-bottom: 10px;">';
echo '<div class="z-depth-1-half mt-3" id="thumb-output'.$i.'"></div>';
echo '<div class="d-flex justify-content-center">';
echo '<div class="custom-file">';
echo '<input type="file" data-index="'.$i.'" name="imageupload[]" class="custom-file-input" aria-describedby="inputGroupFileAddon'.$i.'">';
echo '<label class="custom-file-label" for="inputGroupFile'.$i.'">IMG '.$i.'</label>';
echo '</div>';
echo '</div>';
echo '</div>';
echo '</div>';
echo '<div class="col-xl-8 col-lg-8 col-md-6 mt-4">';
echo '<label for="imagedescription'.$i.'">Description IMG '.$i.'</label>';
echo '<input type="text" name="imagedescription[]" class="form-control mt-2" id="imagedescription'.$i.'" aria-describedby="ImageDescription'.$i.'" style="margin-bottom: 0px;">';
echo '<input type="hidden" name="imgcount" value="'.$i.'">';
echo '</div>';
echo '</div>';
}
and this page that "take" and process the datas.
for($i = 0; $i < $count_tmp_name_array; $i++){
$extension = pathinfo($name_array[$i] , PATHINFO_EXTENSION);
$j=$i+1;
$imgname = $albumtitle."-".$j.".".$extension;
if(move_uploaded_file($tmp_name_array[$i], $target_dir.$imgname)){
$photo_decription = $_POST['imagedescription['.$i.']'];
print_r ($photo_decription);
echo "</br>";
}
Basically what I need to do is to assign the varous values of the array imagedescription[] to the relative image (to be upoaded to the DB). Something like:
[...]
imagedescription[1] -> imageupload[1];
imagedescription[2] -> imageupload[2];
imagedescription[3] -> imageupload[3];
[etc]
The rest is working good but when I try to print the value of $photo_decription or $_POST['imagedescription['.$i.']'] (either with echo or print_r, it doesn't make difference) I recieve the error "Undefined Index for imagedescription[1]", "Undefined Index for imagedescription[2]", "Undefined Index for imagedescription[3]", etc.