Jump to content

Another question


Schlo_50

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.