Schlo_50 Posted May 14, 2008 Share Posted May 14, 2008 Hello again, I have an upload form with 3 file fields. I want to check if any of them have been used, and if they have create an array with their details. I have written some code but I wanted to see if it made sense, or whether it would need some adjustment. $aname = $_FILES['ufile']['name'][0]; $bname = $_FILES['ufile']['name'][1]; $cname = $_FILES['ufile']['name'][2]; if (isset($aname) && isset($bname)) { $fn = array('$aname', '$bname'); elseif (isset($aname) && isset($bname) && isset($cname)) { $fn = array('$aname', '$bname', '$cname'); else { print "Files have been selected incorrectly."; } foreach ($fn as $fns) { $fext = substr($fns, strrpos($fns, '.')); $jpg = ".jpg"; $jpeg = ".jpeg"; if ($fext == $jpg || $fext == $jpeg) { // || = or print "foo"; } Thanks in advance guys! (again) Link to comment https://forums.phpfreaks.com/topic/105577-another-question/ Share on other sites More sharing options...
Schlo_50 Posted May 14, 2008 Author Share Posted May 14, 2008 (I have just realised I've forgotten some curly braces!) Please ignore that..lol Link to comment https://forums.phpfreaks.com/topic/105577-another-question/#findComment-540829 Share on other sites More sharing options...
conker87 Posted May 14, 2008 Share Posted May 14, 2008 Repeat after me: I will check my code for curly brackets I will check my code for curly brackets I will check my code for curly brackets Link to comment https://forums.phpfreaks.com/topic/105577-another-question/#findComment-540832 Share on other sites More sharing options...
Schlo_50 Posted May 14, 2008 Author Share Posted May 14, 2008 lol, Have done now! Have also tested the code and have found out variables in an array need not have singles quotes surrounding them! I now have: $aname = $_FILES['ufile']['name'][0]; $bname = $_FILES['ufile']['name'][1]; $cname = $_FILES['ufile']['name'][2]; if (isset($aname)) { $fn = array($aname); } elseif (isset($aname) && isset($bname)) { $fn = array($aname, $bname); } elseif (isset($aname) && isset($bname) && isset($cname)) { $fn = array($aname, $bname, $cname); } else { print "Files have been selected incorrectly."; } foreach ($fn as $fns) { print $fns; } However, my loop will not print more than one file's details if I upload more than one file. Whats wrong with my if else statements? Link to comment https://forums.phpfreaks.com/topic/105577-another-question/#findComment-540839 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.