我有一个脚本添加乐队名称+乐队的图片。这是我的控制者:
public function addBand()
{
$config['upload_path'] = './uploads/bands';
$config['allowed_types'] = 'gif|jpg|png';
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('picture')) {
$error = array('error' => $this->upload->display_errors());
$this->session->set_flashdata('error', $error);
$this->load->view('concerts/index');
}
else {
$upload_data = $this->upload->data();
$file_name = $upload_data['file_name'];
$data = array(
'bName' => $this->input->post('name'),
'bPicture' => $file_name
);
$this->band_model->insertBand($data);
$this->session->set_flashdata('success', "Groupe ajouté");
redirect('');
}
}
这个控制器工作得很好!所以。现在我在jquery中添加Cropper插件。我得到“#imagebase64”的价值,他给我的结果很好。之后,我把代码从这个数据64创建图片。他工作得很好。现在我想用Codeigniter添加这个代码..它不起作用:
public function addBand()
{
$config['upload_path'] = './uploads/bands';
$config['allowed_types'] = 'gif|jpg|png';
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
$img64 = $this->input->post('imagebase64');
$exploded = explode(',', $img64, 2);
$encoded = $exploded[1];
$decoded = base64_decode($encoded);
$img_handler = imagecreatefromstring($decoded);
$finalImg = imagepng($img_handler, "png.png");
if ( ! $this->upload->do_upload('picture')) {
$error = array('error' => $this->upload->display_errors());
$this->session->set_flashdata('error', $error);
$this->load->view('concerts/index');
}
else {
$finalImg = $this->upload->data();
$file_name = $finalImg['file_name'];
$data = array(
'bName' => $this->input->post('name'),
'bPicture' => $file_name
);
$this->band_model->insertBand($data);
$this->session->set_flashdata('success', "Groupe ajouté");
redirect('');
}
}
当我在“$ finalImg = $ this-> upload-> data();”之前制作$ finalImg juste的var_dump时,我有“boolean:1”,当我在 $ file_name = $ finalImg ['file_name']之后创建var_dump juste; 我有:
'file_name' => string 'eca69e25e70c469e73a5bfa114c5a87d.png' (length=36)
'file_type' => string 'image/png' (length=9)
'file_path' => string 'C:/wamp64/www/concerts/uploads/bands/' (length=37)
'full_path' => string 'C:/wamp64/www/concerts/uploads/bands/eca69e25e70c469e73a5bfa114c5a87d.png' (length=73)
'raw_name' => string 'eca69e25e70c469e73a5bfa114c5a87d' (length=32)
'orig_name' => string 'Sans_titre-1.png' (length=16)
'client_name' => string 'Sans titre-1.png' (length=16)
'file_ext' => string '.png' (length=4)
'file_size' => float 368.2
'is_image' => boolean true
'image_width' => int 784
'image_height' => int 419
'image_type' => string 'png' (length=3)
'image_size_str' => string 'width="784" height="419"' (length=24)
那么,我如何在PHP中生成图片并使用codeigniter上传此图片?谢谢!