2017-03-29 4 views
0

PHP-Code:Codeigniter jQuery-Datei-Upload nicht funktioniert

$files = json_decode($this->input->post('Image')); 
echo "<pre>"; 
print_r($files); 
echo "</pre>"; 

jQuery-Code:

var image = []; 
for(var i = 1; i <= $("#removeimagefield").attr('data-id'); i++){ 
    image.push($("#imageupload"+i).val()); 
} 
console.log(JSON.stringify(image)); 

HTML-Code:

<form role="form" enctype="multipart/form-data" accept-charset="utf-8" name="formname" id="formname" method="post" action=""> 
    <input type="file" class="default" id="imageupload1"> 
</form> 

AJAX Funktion:

addproperty = {Image: JSON.stringify(image)} 
    $.ajax({ 
    method: "POST", 
    url: formsubmission, 
    data: addproperty, 
    async : false, 
    cache : false, 
    contentType : false, 
    processData : false, 
    success: function(response){ 
     console.log(response); 
    } 
    }); 

Console Nachricht:

["C:\\fakepath\\abhishek.jpg","C:\\fakepath\\krunal.jpg","C:\\fakepath\\nitin.jpg"] 

Ich versuche Bilddatei Codeigniter Controller zu laden. aber wenn ich Wert von $ files drucke. als es leeres Array anzeigt.

+0

wo in der Steuerung der Code ist? :/ –

Antwort

0

diesen Code Versuchen Sie, und Ihre Datei im Controller mit einfachen $ _FILES erhalten [ 'img_file'] [ 'file_name']

$(document).ready(function (e) { 
        var file_name = $('#id_file_input').prop('files')[0]; 
        var form_data = new FormData(); 
        form_data.append('img_file', file_data); 
        $('#vid_file').prop('disabled', true); 
        $.ajax({ 
        url: '<?php echo base_url(); ?>Controller/function_name', 
         dataType: 'text', 
         cache: false, 
         contentType: false, 
         processData: false, 
         data: form_data, 
         type: 'post', 
          success: function (response) { 

         } 
        }); 
        }); 
+0

man alles ist dynamisch es ist ein nicht statisch. Leute können neues Feld für Bild hinzufügen. –

Verwandte Themen