问题描述
我正在使用Codeigniter 3, Ion-Auth 和Bootstrap 4开发社交网络应用程序。您可以看到 Github repo HERE 。
更新
我现在有:
.round {
position: relative;
}
.round label {
background-color: #fff;
border: 1px solid #ccc;
border-radius: 50%;
cursor: pointer;
height: 20px;
left: 0;
position: absolute;
top: 0;
width: 20px;
}
.round label:after {
border: 2px solid #fff;
border-top: none;
border-right: none;
content: '';
height: 6px;
left: 3px;
opacity: 0;
position: absolute;
top: 6px;
transform: rotate(-45deg);
width: 12px;
}
.round input[type='checkbox'] {
visibility: hidden;
}
.round input[type="checkbox"]:checked + label {
background-color: #66bb6a;
border-color: #66bb6a;
}
.round input[type="checkbox"]:checked + label:after {
opacity: 1;
}
上面的代码在将文件名插入if ($this->form_validation->run() === TRUE)
{
//more code here
$config['upload_path'] = './assets/img/avatars';
$config['file_ext_tolower'] = TRUE;
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = 1024;
$config['max_width'] = 1024;
$config['max_height'] = 1024;
$config['encrypt_name'] = TRUE;
$this->load->library('upload',$config);
if (!$this->upload->do_upload('userfile')){
$error = array('error' => $this->upload->display_errors());
$file_name = null;
} else {
$file_name = $this->upload->data('file_name');
}
$additional_data = [
'first_name' => $this->input->post('first_name'),'last_name' => $this->input->post('last_name'),'avatar' => $file_name,'company' => $this->input->post('company'),'phone' => $this->input->post('phone'),];
}
列之前正确地对其进行了哈希处理,但是上传本身从未发生。
原始代码
我正在使用以下代码上传用户图片(头像)
avatar
正如您在else块中看到的那样,我正在通过将其添加当前时间戳和哈希值来更改原始文件名。
问题是图像文件本身在上传之前未相应重命名。它以原始名称上传(图像未存储在if ($this->form_validation->run() === TRUE)
{
//more code here
$config['upload_path'] = './assets/img/avatars';
$config['file_ext_tolower'] = TRUE;
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = 1024;
$config['max_width'] = 1024;
$config['max_height'] = 1024;
$this->load->library('upload',$config);
if (!$this->upload->do_upload('userfile')){
$error = array('error' => $this->upload->display_errors());
$file_name = null;
} else {
// get filename with extension
$file_name = $_FILES['userfile']['name'];
// get filename without extension
$file_name_clean = explode('.',$file_name)[0];
// get filename extension
$file_ext = explode('.',$file_name)[1];
//Add timestamp to filename and hash it
$file_name = md5($file_name.date('m-d-Y_H:i:s'));
// add extension
$file_name = $file_name_clean . '.' . $file_ext;
}
$additional_data = [
'first_name' => $this->input->post('first_name'),];
}
中。)
为什么会这样?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)