Загрузить и изменить размер в CodeIgniter

Я загружаю и изменяю размеры нескольких изображений, но этот код хорошо работает для 1 файла, если я загружаю 2 или более файла, он изменит первый размер изображения как полностью черный, а все остальные фотографии будут загружены без изменений.

function do_upload()
{
$files = $_FILES;

$cpt = count($_FILES['userfile']['name']);

for($i=0; $i<$cpt; $i++)
{

$_FILES['userfile']['name']= $files['userfile']['name'][$i];
$_FILES['userfile']['type']= $files['userfile']['type'][$i];
$_FILES['userfile']['tmp_name']= $files['userfile']['tmp_name'][$i];
$_FILES['userfile']['error']= $files['userfile']['error'][$i];
$_FILES['userfile']['size']= $files['userfile']['size'][$i];

$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width']  = '1024';
$config['max_height']  = '768';

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

if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());

$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());

$path=$data['upload_data']['full_path'];
$q['name']=$data['upload_data']['file_name'];

$configi['image_library'] = 'gd2';
$configi['source_image']   = $path;
$configi['maintain_ratio'] = TRUE;
$configi['width']  = 75;
$configi['height'] = 50;

$this->load->library('image_lib', $configi);

$this->image_lib->resize();

$this -> load -> view('upload_success', $q);

}
}
}

где я что-то упустил, эта функция изменения размера не работает точно.

1

Решение

Ниже этой линии

$path=$data['upload_data']['full_path'];

записывать

echo $path;

тогда проверь какой выход?

0

Другие решения

пожалуйста попробуйте ниже

function do_upload(){

$this->load->library('upload');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width']  = '1024';
$config['max_height']  = '768';

foreach($_FILES['userfile'] as $key => $value)
{

if( ! empty($key['name']))
{

$this->upload->initialize($config);

if ( ! $this->upload->do_upload($key))
{
$error['error'] = $this->upload->display_errors();

$this->load->view('pages/uploadform', $error);
}
else
{
$data[$key] = array('upload_data' => $this->upload->data());

$this->load->view('pages/uploadsuccess', $data[$key]);}
}

}

}
}

0