在codeigniter

时间:2019-05-07 15:37:06

标签: php codeigniter dynamicmvc

您已添加$ config ['encrypt_name'] = TRUE;对于上载代码,因为某些用户图像被称为空格,并且会导致提升问题

上传文件后,其名称已更改,但我尝试使用文件名将其发送到数据库 这条路 $ img1 = $ _FILES ['img1'] ['name']; 但是我在更改之前得到了原始文件名

  $config['upload_path']          = './uploads/';
  $config['allowed_types']        = 'gif|jpg|png';
  $config['max_size']             = 2000;
  $config['max_width']            = 1024;
  $config['max_height']           = 768;
  $config['overwrite']        = FALSE;
  $config['encrypt_name'] = TRUE;

  $this->load->library('upload', $config);

2 个答案:

答案 0 :(得分:0)

如果您遍历每张照片并使用$ _FILES ['file_name']初始化图片库,这将对您有帮助

 $config['upload_path']          = './uploads/';
 $config['allowed_types']        = 'gif|jpg|png';
 $config['max_size']             = 2000;
 $config['max_width']            = 1024;
 $config['max_height']           = 768;
 $config['overwrite']        = FALSE;
 $config['encrypt_name'] = TRUE;

 $this->load->library('upload', $config);

 $this->upload->do_upload('file_name');
 $image_uploaded = $this->upload->data();

 $filename = pathinfo($image_uploaded['full_path']);

 $insert['photo'] = $filename['basename'];

 $this->db->insert('your_table', $insert);

答案 1 :(得分:0)

不要退回到$_FILE超全局变量。由于您正在使用CI,因此请坚持使用CI的上载包装器

将上传过程的输出分配给这样的变量:

$your_variable = $this->upload->data();

这样做,您将在新创建的$your_variable数组中获取所有上传数据:

$your_variable['file_name'] // encrypted name
$your_variable['file_type'] // MIME type such as image/jpeg or application/pdf
$your_variable['file_path'] // self explanatory
$your_variable['raw_name'] // encrypted name without the extension
$your_variable['orig_name'] // original name
$your_variable['client_name'] // name the file had on the client's computer
$your_variable['file_ext'] // self explanatory
$your_variable['file_size'] // self explanatory. Size in Kb
$your_variable['is_image'] // 1 if yes, 0 otherwise
$your_variable['image_width'] // only for images
$your_variable['image_height'] // only for images
$your_variable['image_type'] // only for images
$your_variable['image_size_str'] // only for images

我很确定从CI 3.1.10起您就可以得到这些(但是我可能已经忘记了一对,如果抱歉,我对此表示歉意)

出于您的目的,您需要['file_name']元素。 返回$_FILE超全局将无法正常工作,因为CI不会修改其值