2010-08-12 7 views
1

나는 오전 12시 30 분에 인쇄 할 때 $_FILES과 같은 배열을 가지고 있습니다.PHP의 foreach 문제

Array ([ANTI-HAV__TOTAL] => Array ([name] => Array ([0] => Firefox_wallpaper1.png [1] => Firefox_wallpaper2.png) [type] => Array ([0] => image/png [1] => image/png) [tmp_name] => Array ([0] => /tmp/phpr92AvZ [1] => /tmp/phpxmzia3) [error] => Array ([0] => 0 [1] => 0) [size] => Array ([0] => 353750 [1] => 353750))) 

하지만

foreach($_FILES['ANTI-HAV__TOTAL']['name'] as $value1) 

처럼 foreach 문을 사용하려고하면 그것은

Warning: Invalid argument supplied for foreach() 

가 어떻게이 문제를 해결합니까라고?

이 액션 부분에 대한 컨트롤러 내 양식

<?php 
$myresult .= '<div class=\'fieldForm\'>'; 
$myresult .= '<form id=\'lab_form\' enctype=\'multipart/form-data\' method=\'POST\' action =\''.$this->url(array('controller'=>'lab', 'action' =>'uploadsave')).'\'>'; 
$myresult .= '<fieldset>'; 
$myresult .= '<legend>Lab Upload Form</legend>'; 
foreach($labtests_break as $key => $value) 
{ 
$nvalue = str_replace(' ','__',trim($value)); 
$nvalue = str_replace('(','___',trim($nvalue)); 
$nvalue = str_replace(')','____',trim($nvalue)); 
if(!in_array($value,$gotImages2)) 
{  
$myresult .= '<div class=\'field50Pct\'>'; 
/*$myresult .= '<input type=\'button\' id=\''.$nvalue.'Add\' value=\'Add Another '.$value.' Image\' onclick=\'addElement(this.id)\' />'; 
$myresult .= '<input type=\'button\' id=\''.$nvalue.'Del\' value=\'Remove'.$value.' Image\' onclick=\'removeElement(this.id)\' disabled=\'disabled\/>';*/ 
$myresult .= '</div>'; 
$myresult .= '<div class=\'clear\'></div>'; 
$myresult .= '<div class=\'clear\'></div>'; 
$myresult .= '<div class=\'field50Pct\'>'; 
$myresult .= '<div class=\'fieldItemLabel\'>'; 
$myresult .= '<label for=\'\'>'.$value.'</label>'; 
$myresult .= '</div>'; 
$myresult .= '<div class=\'fieldItemValue\'>'; 
$myresult .= '<div id=\''.$nvalue.'input1\' class=\''.$nvalue.'clonedInput\'>'; 
$myresult .= '<input type=\'file\' name=\''.$nvalue.'[]\' id=\''.$nvalue.'1\' class="multi">'; 
//$myresult .= '<input type=\'button\' style=\'width:50px;padding:2px;margin-left:10px;\' value=\'Clear\' onclick=\'clearField(this)\'/>'; 
$myresult .= '</div>'; 
$myresult .= '</div>'; 
$myresult .= '</div>'; 
$myresult .= '<div class=\'clear\'></div>'; 
} 
} 
$myresult .= '<input type=\'hidden\' name=\'visitId\' value=\''.$visitId.'\' >'; 
$myresult .= '<input type=\'hidden\' name=\'patientId\' value=\''.$patientId.'\' >'; 
$myresult .= '<input type=\'hidden\' name=\'tests\' value=\''.$labtests.'\' >'; 
$myresult .= '<input type=\'submit\' value=\'upload\'>'; 
$myresult .= '</fieldset>'; 
$myresult .= '</form>'; 
$myresult .= '</div>'; 
echo $myresult; 
?> 

입니다.

public function uploadsaveAction() 
{ 
$this->view->homeId = "current"; 
     $this->view->homeUrl = $this->view->url(array('controller' => 'lab', 'action' =>'index')); 
     $this->view->labMenu = 'yes'; 
     $this->view->patientsId = ""; 
     $this->view->settingsId = ""; 
     $this->view->settingsURL = ""; 

     $request = $this->getRequest(); 
if($request->isPost()) 
     { 
       $visitId  = $_POST['visitId']; 
       $patientId  = $_POST['patientId']; 
       $tests   = $_POST['tests']; 
       $tests_break = explode(',',$tests); 
       foreach($tests_break as $key=>$value) 
       { 

         $nvalue = str_replace(' ','__',trim($value)); 
         $nvalue = str_replace('(','___',trim($nvalue)); 
         $nvalue = str_replace(')','____',trim($nvalue)); 

         //for($i= 0; $i<=$limit ; $i++) 
         echo '<br/>'; 
         print_r($_FILES); 
         echo '<br/>'; 
         echo $nvalue; 
         foreach($_FILES[$nvalue]['name'] as $value1) 
         { 
         $key_found = array_search($value1, $_FILES[$nvalue]['name']); // $key = 2; 
         /*$check    = $nvalue.$i;*/ 
         $filename  = $_FILES[$nvalue]['name'][$key]; 
         $tmpname  = $_FILES[$nvalue]['tmp_name'][$key]; 
         //echo $check; 
         //echo '<br/>'; 
         if($filename != '') 
         { 

         $structure = '/var/www/html/hms-work/public/visit_images/'.$patientId.'/'.$visitId; 

         if(!is_dir($structure)) 
         { 
         if (!mkdir($structure, 0777, true)) 
         { 
          die('Failed to create folders...'); 
         } 
         } 
         /** is_dir if ends here **/ 
         if(is_dir($structure)) 
         { 
           if($_FILES[$nvalue]['error'][$key] == 0) 
    if(file_exists($structure.'/'.$filename)) 
             { 

             } 
             else 
             { 
              if(move_uploaded_file($tmpname, "$structure/$filename")) 
               { 
               $imageUpload = new Application_Model_Imageupload(); 
               $imageUploadMapper = new Application_Model_ImageuploadMapper(); 

               $imageUpload->setVisitid($visitId) 
                   ->setType($value) 
                   ->setImagename($filename) 
                   ->setCreateddate(date('Y-m-d H:i:s')) 
                   ->setCreatedby($this->session->userId); 

               $imageUploadMapper->save($imageUpload); 
               $this->view->message = 'Succesfully uploaded the images'; 

               } 
             } 
           } 
         } 

         } 
         } 

       } 
//    print_r($_POST); 
     //  print_r($_FILES); 

     } 
     else 
     { 
     } 
} 
+1

당신은'var_dump ($ _ FILES [ 'ANTI-HAV__TOTAL'] [ 'name'])'을 추가 할 수 있습니까? – mathk

+0

'$ a = $ _FILES [ 'ANTI-HAV__TOTAL'] [ 'name'];'그렇다면 foreach ($ a as ...'? – jtbandes

+0

@jtbandes - 나는 같은 오류가 발생했습니다. @mathk - vardump가 어떤 것을 인쇄합니다. array (2) {[0] => string (22) "Firefox_wallpaper1.png"[1] => string (22) "Firefox_wallpaper2.png"} – Hacker

답변

1

시도

var_dump($_FILES['ANTI-HAV__TOTAL']); 

와 키는 처음에 올 경우를 참조하십시오.