我使用CI 2.2制作了带附件/文件上传的简单表单。一切正常,除了iphone safari浏览器。当人们从iphone safari附加图像时,文件名变成了image.jpg。这导致来自不同的人的附件保持显示相同图像的问题。
我使用CI提供的文件名加密但仍然没有运气。
以下是模型:
从字段获取值的函数:
function check_field()
{
$ship_date = $this->input->post('date');
$image_data = $this->upload->data();
$field_data = [
'ship_date' => $ship_date,
'ship_boxes' => $this->input->post('boxes'),
'ship_attach' => $image_data['file_name'],
'image_path' => $image_data['file_path'],
'ship_req_fund' => $this->input->post('option'),
'ship_amount_req' => $this->input->post('amount'),
'ship_emp_id' => $this->session->userdata('id')
];
$this->db->insert('shipment', $field_data);
}
附件功能
function attachment()
{
$config['upload_path'] = 'uploads/';
$config['allowed_types'] = 'gif|jpg|png|zip|rar|pdf';
$config['max_size'] = '3000';
$config['max_width'] = '2000';
$config['max_height'] = '2000';
$config['encrypt_name'] = true;
$this->upload->initialize($config);
}
向电子邮件发送消息:
function send_message()
{
$config = [
'protocol' => 'mail',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => '*******@gmail.com',
'smtp_pass' => '*******',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
];
$image_data = $this->upload->data();
$image_link = $image_data['client_name'];
$message = '<h3>Below is the shipment data you have submitted.</h3>';
$message .= '<p><b>Shipment date</b>: ' . $this->input->post('date') . '</p>';
$message .= '<p><b>Number of boxes</b>: ' . $this->input->post('boxes') . '</p>';
if($this->upload->data())
{
$message .= '<p></b>Attachment</b>: <a href="' . base_url() . 'uploads/' . $image_link . '">Click Here</a></p>';
}
else
{
$message .= '<p></b>Attachment</b>: No attachment</p>';
}
if($this->input->post('option') == 1)
{
$message .= '<p><b>Request fund</b>: Yes</p>';
$message .= '<p><b>Amount of funds requested</b>: $' . $this->input->post('amount') . '</p>';
}
else
{
$message .= '<p><b>Request fund</b>: No</p>';
}
$this->email->initialize($config);
$this->email->set_newline("\r\n");
$this->email->from('*****@gmail.com', '*****');
$this->email->to($this->session->userdata('email'));
$this->email->subject('Shipment detail');
$this->email->message($message);
$this->email->send();
}
}
过去有没有人遇到同样的问题,或者我错误地设置了?如果这真的是由浏览器引起的,在iphone safari中解决文件上传的任何方法?
谢谢,
答案 0 :(得分:0)
我将此功能用于您遇到的同样问题 -
<?php
get_filename($filename)
{
$fparts= explode(".",$filename);
$extension = $fparts[count($fparts)-1];
unset($fparts[count($fparts)-1]);
$filenamewoextension=implode(".", $fparts);
counter=0;
while(file_exists($filename))
{
$filename = $filenamewoextension . $counter . $extension;
}
return $filename;
}
答案 1 :(得分:0)
为名称创建UUID。依靠客户提供的名称是独一无二的,这不是一个好习惯。