Bhanu Prakash Pandey
Bhanu Prakash Pandey

Reputation: 3785

how to validate an image array in php

<input name= "p_image[]" type="file" id="p_image[]">

i need that user upload atleast one image and if it doesn't it show error..

Upvotes: 0

Views: 215

Answers (2)

PHP
PHP

Reputation: 1709

<?php

   if(!isset($_POST['p_image'])) { 

          //failure messgae

   }
?>

Upvotes: 0

Jacob Relkin
Jacob Relkin

Reputation: 163318

You can check the count of the array, and if it's equal to 0, then throw an error:

<?php

   if(isset($_POST['p_image'])) { 
      if(!(count($_POST['p_image']))) {
          //throw error here...
      }
   } else {
     //throw another error here...
   }
?>

Upvotes: 2

Related Questions