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
Post a Comment