skl  
          
              
                October 27, 2023, 11:45am
               
              1 
           
         
        
          Hello,
         
        
           
         
            
       
      
        
          
          
            skl  
          
              
                November 14, 2023,  3:16pm
               
              3 
           
         
        
          in my View i have:
echo Html::beginForm(['picupload', 'kStammPerson' => $model->kStammPerson], 'post', ['enctype'=>'multipart/form-data' ,'id' => 'picform']);
echo Html::fileInput('pic', null, ['accept' => '.jpeg,.jpg', 'id' => 'picinput']);
echo Html::SubmitButton('uploaden', ['class' => 'btn btn-secondary','id'=>'picuploadbtn']);
echo Html::endForm();
echo '<div id="result"></div>';
in included js file i have:
function addPic(currentValue, index, arr){
  document.getElementById('result').innerHTML += '<img src=downloadpic?id='+currentValue.id+'>';
}
form.onsubmit =function(event){
  event.preventDefault();
  var formData = new FormData();
  formData.append("pic", fileSelect.files[0]);
  
  const urlParams = new URLSearchParams(window.location.search); 
  
  $.ajax({
      url: "picupload?kStammPerson="+urlParams.get('kStammPerson'),  //Server script to process data
      type: 'POST',
      
      data: formData,
      success: function(response) {
        const picids = JSON.parse(response);
        document.getElementById('result').innerHTML='';
        picids.forEach(addPic);
      },
      error: function(){
          alert('ERROR at PHP side!!');
      },
      cache: false,
      contentType: false,
      processData: false
  });
};
in Controller i have :
public function actionPicupload($kStammPerson = null)
    {
       return json_encode($_FILES);
}
what i get is that actionPicupload returns an empty array.
         
        
           
         
            
       
      
        
          
          
            evstevemd  
          
              
                November 14, 2023,  5:31pm
               
              4 
           
         
        
          Please use code tags. The code is unreadable for that reason. That </> icon on your comment editor
         
        
           1 Like 
         
         
            
       
      
        
          
          
            evstevemd  
          
              
                November 16, 2023,  3:13pm
               
              5 
           
         
        
          I see now. Your problem is well articulated as well as solution provided.
  
  
      
     
  php, ajax, yii2