2012-03-23 7 views
0

CodeIgniterの私はこのようなjqueryのコードを持っている:jQueryの、ファイルのアップロードと2.1問題

$(parent).on('click', '.izmeni', function() { 

     var clone = $(this).parent().clone(); 

     var name = $(this).siblings('.name').text(); 
     var surname = $(this).siblings('.surname').text(); 
     var info = $(this).siblings('.info').text(); 
     var email = $(this).siblings('.email').text(); 
     var phone = $(this).siblings('.phone').text(); 
     var date_birth = $(this).siblings('.date_birth').text(); 
     var id_lok = $(this).siblings('.lokacija').val();  
     var id = $(this).siblings('.id').val();    

     <?php $attributes = array('class' => 'update_form'); ?> 

     $(this).hide(); 
     $(this).siblings('.permission').hide(); 
     $(this).siblings('strong').hide(); 
     $(this).parent().wrapInner('<?php echo form_open_multipart('upload/do_upload', $attributes);?></form>'); 
     $(this).parent().prepend('<input type="file" name="userfile" size="20" />'); 
     $(this).parent().append('<div class="lokacija"></div>'); 
     $(this).parent().append('<select name="pol"><option value="m">Muški</option><option value="f">Ženski</option></select>');   
     $(this).parent().append('<input type="submit" value="Submit" />'); 
     $(this).parent().append('<a id="otkazi">Otkazi</a>'); 

     $(this).siblings('.name').replaceWith('<input name="name" value="' + name + '" />'); 
     $(this).siblings('.surname').replaceWith('<input name="surname" value="' + surname + '" />'); 
     $(this).siblings('.info').replaceWith('<textarea name="info">' + info + '</textarea>');  
     $(this).siblings('.email').replaceWith('<input name="email" value="' + email + '" />'); 
     $(this).siblings('.phone').replaceWith('<input name="phone" value="' + phone + '" />');   
     $(this).siblings('.date_birth').load("<?php echo base_url() ?>form/date_birth", {'date' : date_birth}); 
     $(this).siblings('.lokacija').load("<?php echo base_url() ?>form/location", {'id' : id_lok}); 

     $(this).siblings('#otkazi').click(function(){ 
      $(this).parents("div:first").replaceWith(clone); 
      $(this).show(); 
     }); 

     $(".update_form").submit(function(){ 
      data = $(this).serialize(); 
      console.log(data); 
      forma = $(this); 
      $.ajax({ 
       type : "POST", 
       data : data, 
       url : "<?php echo base_url() ?>/user/update_person", 
       success : function(){ 
        forma.slideUp('slow'); 
        $("#all_users").fadeOut('slow', function(){ 
         $(this).empty().load("<?php echo base_url() . "ajax/get_all_users" ?>", function(){ 
          $(this).hide().slideDown('slow'); 
         }) 
        }); 
       } 
      }) 
      return false; 
     }); 
    }); 

とPHPコード:

function update_person(){ 

      if($this->person_img_upload() != false){$data['picture'] = $this->person_img_upload();}else{echo "131231";} 

       $data = array(
      'name' => $_POST['name'], 
      'surname' => $_POST['surname'], 
      'telephone' => $_POST['phone'], 
      'info' => $_POST['info'],    
      'location' => $_POST['location'], 
      'gender' => $_POST['pol'], 
      'date_birth' => $this->date() 
       ); 
      $id = $_POST['id']; 
      echo $id; 
      $this->db->where('id_person', $id); 
      $this->db->update('person', $data); 
      $this->update_user($id); 
      } 


function person_img_upload(){ 
       $config = array (
      'allowed_types' => 'jpg|jpeg|png|gif', 
      'upload_path' => $this->path 
     ); 
     $this->load->library('upload', $config); 
     $this->upload->do_upload(); 
     $q = $this->upload->data(); 
     if (!$this->upload->do_upload()){ 
      $error = array('error' => $this->upload->display_errors()); 
      $this->load->view('upload_form', $error); 
      return false;} 
     else{ 
      $this->upload->do_upload(); 
      $q = $this->upload->data();   
      return $q['file_name']; 
       }  
      } 

jQueryのページの要素を交換され、それがどこのユーザーフォームを作成します彼のデータを更新することができます。 (これは正常に動作していますが、画像部分がない状態でアップデートが動作しています)。私も、それは(フォームはjqueryのを介して作成されていません)正常に動作している

function person_img_upload()

を使用する新しいユーザーを作成するためのフォームを持っている

You did not select a file to upload

:私はイメージを更新しようとすると、私はこのエラーを取得します。何が問題だと思われますか?

答えて

1

ファイルはajaxリクエストでアップロードされません。フォーム全体を提出する必要があります。そうしたい場合は、iframe経由でフォームを投稿することができます。

+0

これは私の知識レベルを超えています。シンプルなPHPファイルのアップロードは、今のところ行う必要があります。 – Sasha

関連する問題