Hi All,
Im building a CMS where 3 images need to be uploaded. I'm trying to validate by checking for 2 things (at least for now). One, that it's not empty and
Two, the image must be a .gif
3 images in an upload means a 2 dimensional array. I've accessed via 2 foreach loops but am trying to figure out the syntax isolate and check the individaul key => value pairs.
i want to access the [error] and test if it's 4 (means it's empty), and also the [type] to see if it's a .gif or not. how can i do that?
any help would be great, thanks!
my code so far is this,
$imgArr = array($add_acchdr_off, $add_acchdr_on, $add_main_pic);
foreach ($imgArr as $Img) {
foreach($Img as $key => $val) {
echo $key . ' ' . $val;
//put some val code here
}
}
I know this doesn't answer your question, but do you have any links on how to go about uploading multiple images? I'm working on a 2 image uploader and I want it to upload each image in a separate locations. Help would be much appreciated!
Almost!, in fact i've answered my own question re: validating. Next i have to script how to move from temp to designated folder. I will post later if you want, let me know
First off, to understand the Super Global Files array, i would do this, it shows you everything
don't know if this is 100%, i've distilled from my project and cut out stuff not relevant to img uploads.
PHP Code:
function valImg($img, &$theErrArr) {
if($img['error'] == 4 ){
//echo 'Img is empty, please choose an image';
array_push($theErrArr, 'Img is empty, please choose an image before submitting');
}
if($img['type'] != 'image/gif') {
//echo '<p>Img type must a gif</p>';
array_push($theErrArr, 'Img type must a gif');
}
}
Bookmarks