【发布时间】:2017-10-01 07:54:03
【问题描述】:
我正在通过表单上传图像和文件。但上传后名称并没有改变。在第一次函数调用时,如果名称是 profilePic,那么即使我在 $config['file_name'] 参数中更改名称,这个文件名在每次调用时都保持不变。
函数调用:
function getAndSaveEmployeeDetails() {
$resume = 'resume';
$resume = $this -> do_upload($resume, $employeeID);
$profilePic = 'profilePic';
$profilePic = $this -> do_upload($profilePic, $employeeID);
$cnic = 'cnicScannedImage';
$cnicScannedImage = $this -> do_upload($cnic, $employeeID); }
//上传函数
public function do_upload($uploadedField, $employeeID) {
//$uploadedField = $this -> input -> post('_hidden_field');
if (empty($_FILES[$uploadedField]['name'])) {
$error = "File is empty please choose a file";
return $error;
} else {
$name = '_' . $uploadedField;
$config['file_name'] = $employeeID . $name;
$config['upload_path'] = './uploads/' . $employeeID;
$config['allowed_types'] = 'gif|jpg|jpeg|png|iso|dmg|zip|rar|doc|docx|xls|xlsx|ppt|pptx|csv|ods|odt|odp|pdf|rtf|sxc|sxi|txt|exe|avi|mpeg|mp3|mp4|3gp';
$config['max_size'] = 2048;
$config['max_width'] = 0;
$config['max_height'] = 0;
$this -> load -> library('upload', $config);
if (!is_dir('uploads')) {
mkdir('./uploads', 0777, true);
}
$dir_exist = true;
// flag for checking the directory exist or not
if (!is_dir('uploads/' . $employeeID)) {
mkdir('./uploads/' . $employeeID, 0777, true);
$dir_exist = false;
// dir not exist
} else {
}
if (!$this -> upload -> do_upload($uploadedField)) {
if (!$dir_exist)
rmdir('./uploads/' . $employeeID);
$error = array('error' => $this -> upload -> display_errors());
return $error;
//$this -> load -> view('upload_form', $error);
} else {
$data = array('upload_data' => $this -> upload -> data());
return $path = $data['upload_data']['full_path'];
}
}
}
请查看以下链接中的图片,您将了解行为
These are the file names and it is caching the first name passed in function call
【问题讨论】:
标签: php codeigniter-3