【发布时间】:2018-04-26 07:52:45
【问题描述】:
我已经在 CodeIgniter 中上传了多个文件,它在 localhost 中运行良好,但是当我上传实时服务器时,这些图像不会显示该名称是大写字母。我成功地将小写文件存储在数据库中,但在文件夹中(文件存储位置)我无法更改小写文件名(我认为这是问题所在)。 这是我的控制器
public function create() {
// Check login
if (!$this->session->userdata('logged_in')) {
redirect('users/login');
}
$data['title']= $title = 'Create List';
$path = 'assets/images/posts/';
$this->form_validation->set_rules('title', 'Title', 'required');
$this->form_validation->set_rules('body', 'Body', 'required');
if ($this->form_validation->run() === FALSE) {
$this->load->view('templates/header');
$this->load->view('posts/create', $data);
$this->load->view('templates/footer');
} else {
$this->load->library('upload');
$files = $_FILES;
$image = $files['images']['name'][0];
$img = strtolower($image);
$totimg = count($_FILES['images']['name']);
if (!empty($_FILES['images']['name'][0])) {
$post_image = $_FILES['images'];
if ($this->upload_files($path, $title, $post_image) === FALSE) {
$data['error'] = array('error' => $this->upload->display_errors());
$this->session->set_flashdata('file_size_exceeded', 'Your uploaded file size is too large');
$post_image = 'noimage.jpg';
redirect('posts');
}
if (!isset($data['error'])) {
$this->post_model->create_post($files,$totimg);
$this->session->set_flashdata('post_created', 'Your post has been created');
redirect('posts');
}
}
}
}
private function upload_files($path, $title, $files)
{
$config = array(
'upload_path' => $path,
'allowed_types' => 'jpg|gif|png',
'overwrite' => 1,
'max_size' => 2000,
'remove_spaces' => TRUE
);
$this->load->library('upload', $config);
$images = array();
foreach ($files['name'] as $key => $image) {
$_FILES['images[]']['name']= $files['name'][$key];
$_FILES['images[]']['type']= $files['type'][$key];
$_FILES['images[]']['tmp_name']= $files['tmp_name'][$key];
$_FILES['images[]']['error']= $files['error'][$key];
$_FILES['images[]']['size']= $files['size'][$key];
$this->upload->initialize($config);
if ($this->upload->do_upload('images[]')) {
$this->upload->data();
} else {
return false;
}
}
}
我的模型正在关注
public function create_post($post_image,$totimg){
$this->load->helper('inflector');
$slug = url_title($this->input->post('title'));
$image = implode(',',$post_image['images']['name']);
$file_name = underscore(strtolower($image));
$data = array(
'title' => $this->input->post('title'),
'slug' => $slug,
'body' => $this->input->post('body'),
'user_id' => $this->session->userdata('user_id'),
'post_image' => $file_name
);
return $this->db->insert('posts', $data);
}
【问题讨论】:
-
将文件名更改为数据库中的确切大小写并且应该解决它
-
Linux区分大小写,filename不等于FILENAME -
你试过了吗? $new_name = time().$_FILES["userfiles"]['name']; $config['file_name'] = $new_name;
-
@Mr.Blue 我收到了您的回复,但是如果上传同名文件然后在文件夹文件中更改为文件名(1),则会出现一个问题,但在显示中,它将显示前一个文件,如文件名。 . 我怎么能出来呢
标签: php codeigniter file-upload