这是我发现的一个奇怪的错误。当我的用户上传多张图片时,除了有时候的“tmp目录”外,所有图片都能正常运行。图像上传到服务器的位置被重命名为图像文件名,导致其余图像无法上传,因为' tmp'不再存在。
非常奇怪,我无法重现此错误。我想知道这是否发生在其他任何人身上并且可能知道原因。
我也使用Codeigniter 3.
这是我的do_upload函数的代码:
public function do_upload()
{
$upload_path_url = base_url() . 'imagen/tmp/';
$config['upload_path'] = FCPATH . 'imagen/tmp/';
$config['allowed_types'] = 'jpg|jpeg|png|gif';
$config['max_size'] = '30000';
$this->load->library('upload', $config);
if (!$this->upload->do_upload()) {
$error = array('error' => $this->upload->display_errors());
//$this->load->view('upload', $error);
$this->output
->set_content_type('application/json')
->set_output(json_encode($error));
} else {
$data = $this->upload->data();
// to re-size for thumbnail images un-comment and set path here and in json array
$config = array();
$config['image_library'] = 'gd2';
$config['source_image'] = $data['full_path'];
$config['create_thumb'] = TRUE;
$config['new_image'] = $data['file_path'] . 'thumbs/';
$config['maintain_ratio'] = TRUE;
$config['thumb_marker'] = '';
$config['width'] = 75;
$config['height'] = 50;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
//set the data for the json array
$info = new StdClass;
$info->name = $data['file_name'];
$info->size = $data['file_size'] * 1024;
$info->type = $data['file_type'];
$info->url = $upload_path_url . $data['file_name'];
// ruta thumb para preview
$info->thumbnailUrl = $upload_path_url . 'thumbs/' . $data['file_name'];
$info->deleteUrl = base_url() . 'notas/deleteImage/' . $data['file_name'];
$info->deleteType = 'DELETE';
$info->error = null;
$files[] = $info;
//this is why we put this in the constants to pass only json data
if (IS_AJAX) {
echo json_encode(array("files" => $files));
} else {
$file_data['upload_data'] = $this->upload->data();
// TODO:
$this->load->view('upload/upload_success', $file_data);
}
}
}
如果有人知道原因,我会非常感激。不能告诉你它让我的团队和我想出来的头痛。