You can do it like so — refer to the // {comment}
:
if (isset($_POST["savepics2"])) {
// Set max number of files allowed.
$max_files = 25;
$attachments = get_children( array( 'post_parent' => $v_Id ) );
$count = count( $attachments );
// Check if limit already reached.
if ($count >= $max_files) {
echo 'limit reached';
// If not, then upload the files.
} else {
if (!empty($_FILES['vidPix']['tmp_name'][0])) {
$i = 1;
$files = $_FILES['vidPix'];
foreach ($files['name'] as $key => $value) {
// Check if limit already reached.
if ( $count >= $max_files ) {
echo 'limit reached';
break;
}
// If not, then upload next file.
if ($files['name'][$key]) {
...your code here...
}
$i++;
$count++; // increment the count
}
}
}
}