[英]codeigniter file upload failure with no error
以下是通過codeigniter上傳多個文件的代碼,但這不起作用。 總是拋出錯誤“未選擇文件”
的HTML
<form name="form1" method="post" enctype="multipart/form-data" action="<?php echo base_url(); ?>index.php/dashboard/upload">
<table class="custom">
<tr> <th>Title</th> <th>Image</th> </tr>
<tr><td><input type="text" name="title[]" id="title1"/></td>
<td><input type="file" name="userfile[1][]" multiple id="userfile1" /></td>
<td><input type="button" id="addbutton" value="Add More"></td></tr>
</table>
<table class="custom1" id="repeat-div"></table>
Java腳本
<script>
$(document).ready(function(e) {
var i = $('#repeat-div').size();
var j = i+1;
$('#addbutton').click(function(){
$('<tr><td><input type="text" name="title[]" id="title'+j+'"/></td><td><input type="file" id="userfile'+j+'" name="userfile['+j+'][]" multiple /></td></td></tr>').appendTo($('#repeat-div'));
++i;
j++;
});
});
</script>
控制者
function upload(){
print_r($_FILES);exit;
}
這給出了這樣的輸出。
Array
(
[userfile] => Array
(
[name] => Array
(
[1] => Array
(
[0] => file1.pdf
[1] => file2.pdf
)
[2] => Array
(
[0] => file3.pdf
[1] => file4.pdf
)
)
[type] => Array
(
[1] => Array
(
[0] => application/pdf
[1] => application/pdf
)
[2] => Array
(
[0] => application/pdf
[1] => application/pdf
)
)
[tmp_name] => Array
(
[1] => Array
(
[0] => D:\wamp\tmp\php436C.tmp
[1] => D:\wamp\tmp\php436D.tmp
)
[2] => Array
(
[0] => D:\wamp\tmp\php436E.tmp
[1] => D:\wamp\tmp\php436F.tmp
)
)
[error] => Array
(
[1] => Array
(
[0] => 0
[1] => 0
)
[2] => Array
(
[0] => 0
[1] => 0
)
)
[size] => Array
(
[1] => Array
(
[0] => 191
[1] => 1267
)
[2] => Array
(
[0] => 98591
[1] => 73302
)
)
)
)請建議如何上傳這些文件。
我建議先去File Uploading Class 。現在關於您的問題,因為我知道您沒有將文件字段的名稱傳遞給do_upload()
方法。因此這是代碼中的修改,
foreach($_FILES['userfile']['name'][$i+1] as $file){
//your logic
if ( ! $this->upload->do_upload('images')){
$error = array('error' => $this->upload->display_errors());
exit; }
else
redirect('dashboard/failure');
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.