我在上传多个文件时遇到问题,上传的区域名称不同,并希望在上传之前更改每个区域文件名。 p>
这是HTML表单。 p>
< input type =“file”placeholder =“”name =“profilPic”/>
< input type =“file”placeholder =“”name =“ topPic“/>
code> pre>
这是控制器 p>
$ config ['upload_path'] ='./ uploads'';
$ config ['allowed_types'] ='gif | jpg | png';
$ config ['max_size'] = 100;
$ config ['max_width'] = 1024;
$ config ['max_height'] = 768;
// $ config ['file_name'] = $ this-> session-> sersession [“id”];
$ this-> load-> library(' upload',$ config);
$ profilPic = $ this-> upload-> do_upload('profilPic');
if(!$ profilPic){
$ error = array('error'=> $ this-> upload-> display_errors());
$ this-> session-> set_flashdata(“error”,“profil pic not uploaded =”);
} else {
$ data = array('upload_data'=> $ this-> upload-> data());
$ this-> session-> set_flashdata(“成功”,“profil图片已上传。”); \ n}
$ topPic = $ this-> upload-> do_upload('topPic');
if(!$ topPic){
$ error = array('error'=> $ this-> upload-> display_errors());
$ this-> session-> set_flashdata(“error”,“top pic not a uploaded”);
} else {
$ data = array('upload_data'=> $ this-> upload-> data());
$ this-> session-> set_flashdata(“success”,“此图片已上传。”);
}
code> pre>
注意:图片会上传到目录。 但我想在上传之前重命名每个文件名,如“userID_profil.jpg”和“userID_top.jpg” p>
div>