我想使用codeigniter上传文件,我在我创建的网页上有动态字段 并给它具体的id。但是当我通过下面的代码上传文件时,我得到以下错误。 这是因为它不能识别此id的文件字段但是在检查元素之后 特定id的元素存在。有时大约1mb的小文件上传但是 上传较大的文件会出错。
查看:
function upload_video_Data(a)
{
var formData = new FormData($("#posting_comment_"+a)[0]);
$.ajax({
url: "<?php echo base_url();?>dashboard/do_upload_comment/"+a,
type: 'POST',
async : false,
cache : false,
contentType : false,
processData:false,
data: formData,
success: function(data){
},
error: function(){
alert('Error while request..');
}
});
}
<form name="posting_comment" id="posting_comment_<?=$row1['id']?>">
<input type="file" name="save_movie_<?=$row1['id']?>" class="movie_field" id="movie_<?=$row1['id']?>" />
<input type="hidden" name="file_m_id" value="<?=$row1['id']?>"/>
</span>
<input type="button" class="postbtn" id="submit_movie_<?=$row1['id']?>" value="Upload Video File" onclick = "return upload_video_Data(<?=$row1['id']?>)"/>
</form>
控制器:
public function do_upload_comment($a)
{
$comment_id=$this->input->post('file_m_id');
$output_dir = "./uploads/";
$type="video";
$fileName = $_FILES["save_movie_".$comment_id]["name"];
$extn = pathinfo($fileName, PATHINFO_EXTENSION);
if(!move_uploaded_file($_FILES["save_movie_".$comment_id]["tmp_name"],$output_dir.$fileName))
{
echo 'file upload';
}
else
{
echo 'file not uploaded';
}
}
Severity: Notice
Message: Undefined index: save_movie_76
Filename:controllers/dashboard.php
Line Number: 231
Severity: Notice
Message: Undefined index: save_movie_76
Filename:controllers/dashboard.php
Line Number: 233