0

此代码将捕获异常并上传图像,但是当我在 do_upload 函数中添加调整大小组件时,如果我尝试上传应该可以工作的图像,则会收到 500 错误

<?php

class Upload extends CI_Controller {

  function __construct()
{
    parent::__construct();
    $this->load->helper(array('form', 'url'));
    //form_upload('userfile'); 
}

function index()
{
    $this->load->view('upload_form', array('error' => ' ' ));
}

function do_upload()
{
 if($this->upload->do_upload('userfile'))
{
$fInfo = $this->upload->data(); // get all info of uploaded file
//for image resize
$img_array = array();
$img_array['image_library'] = 'gd2';
$img_array['maintain_ratio'] = TRUE;
$img_array['create_thumb'] = TRUE;
//you need this setting to tell the image lib which image to process
$img_array['source_image'] = $fInfo['full_path'];
$img_array['width'] = 113;
$img_array['height'] = 75;

$this->image_lib->clear(); // added this line
$this->image_lib->initialize($img_array); // added this line
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
 }
 else
 {
  $error = array('error' => $this->upload->display_errors());

                    $this->load->view('upload_form', $error);

  }
}}
4

0 回答 0