我想上传一个多文件,但是我收到一个显示未定义文件的错误。但是相同的代码正在另一个控制器中工作。我用Google搜索但我没有得到任何解决方案。您可以在下面找到错误详情
function upload($name = null){
$fileName = uniqid("ePRIMA");
$fname = $_FILES[$name]['name'];
$ext = pathinfo($fname, PATHINFO_EXTENSION);
$baseName = $fileName.".".$ext;
$config['upload_path'] = _UI;
$config['allowed_types'] = 'gif|jpg|jpeg|png|pdf|xls|xlsx|doc|docx';
$config['file_name'] = $baseName;
$this->load->library('upload', $config);
if ($this->upload->do_upload($name)){
$result['status']=1;
$result['error']="Successfully added documents.";
}
else{
return false;
}
return $baseName;
}
function uploadfile($id){
$fieldName = array("File");
$countarray = count($_FILES['FILES']['name']);
$update = false;
if($countarray!=0){
for($i = 0; $i<=$countarray; $i++){
@$fileName = uniqid("ePRIMA");
@$file = $_FILES['FILES']['name'][$i];
@$ext = pathinfo($file, PATHINFO_EXTENSION);
@$baseName = $fileName.".".$ext;
if(!empty($ext)){
@move_uploaded_file($_FILES['FILES']['tmp_name'][$i], _UI.$baseName);
$data = array("Demand_id"=>$candidateId);
$data['File'] = $baseName;
if(!empty($baseName)){
if ($this->candidate_model->add('demand_document', $data) == TRUE){
$result['status']=1;
$result['message']="Successfull added certificates.";
$update = true;
}
}
}
}
}
foreach($fieldName as $tempName){
$fileName = $this->upload($tempName);
$data = array("Demand_id"=>$id);
$data[$tempName] = $fileName;
if(!empty($fileName)){
if ($this->candidate_model->add('demand_documents', $data) == TRUE){
$result['status']=1;
$result['message']="Successfull added ".ucfirst(strtolower($tempName)).".";
$update = true;
}
}
}
if ($update == TRUE){
header("Content-type: application/json", true);
print_r(json_encode($result));
exit;
}
else
{
$data['custom_error'] = '<div class="form_error"><p>An Error Occured.</p></div>';
$result['status']=0;
$result['error']="Unable to upload file.";
header("Content-type: application/json", true);
print_r(json_encode($result));
exit;
}
}
这就是错误:
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
<h4>A PHP Error was encountered</h4>
<p>Severity: Notice</p>
<p>Message: Undefined index: File</p>
<p>Filename: controllers/demand.php</p>
<p>Line Number: 284</p>
</div>
{"status":0,"error":"Unable to upload file."}