php - Checking that all foreach values meet criteria -


i'm attempting check array provided $_file syntax. script allowing me check individual objects within array when stated.

eg:

$_files['upload1']['tmp_name'][0]; 

the issue:

due fact wanting check of file fields, stating [0] next object isn't i'm looking for, , wondering how check of tmp_name's set dimensions of 1920 x 1080.

note:

the code below works fine, checks singular objects. able check everything, eg: [0], [1], [2], [3] etc etc.

how go doing foreach loop? - i've briefly touched on them before , struggling wrap head around it.

thanks, rich

if(!is_uploaded_file($_files['upload1']['tmp_name'][0])) {         echo "<span class='error'>please fill in of file fields.</span>";    exit(); }  $info = getimagesize($_files['upload1']['tmp_name'][0]); function checksize($info){     if (($info[0] != 1920) || ($info[1] != 1080))          return true;     else         return false; }  if (checksize($info)) {        echo "<span class='error'>all image resolutions must 1920 x 1080.</span>";     exit();  } 

i'm going go ahead , answer own question i've been researching hours:

$countthem = 0; foreach ($files $file) { $file_name = $file; $info = getimagesize($_files['upload1']['tmp_name'][$countthem]); if (($info[0] != 1920) || ($info[1] > 1080)) { echo "<span class='error'>image resolution must 1920 x 1080.</span>"; exit(); } ++$countthem; } 

by counting applying individual object number @ end of ['tmp_name'] array i've been able mirror same number has within array. method applied within foreach loop has allowed me check of file resolutions individually.


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -