在codeigniter php中设置图像的宽度和高度不起作用

avwztpqn  于 2022-12-07  发布在  PHP
关注(0)|答案(1)|浏览(103)

我有一个codeigniter网站,用户可以上传多个图像,我希望所有的图像是相同的大小,我已经在控制器中做了以下代码:

if (isset($_POST['addblog'])) {
    $this->load->library('upload');
    $image = array();
    $ImageCount = count($_FILES['image_name']['name']);

    for ($i = 0; $i < $ImageCount; $i++) {
        $_FILES['file']['name'] = $_FILES['image_name']['name'][$i];
        $_FILES['file']['type'] = $_FILES['image_name']['type'][$i];
        $_FILES['file']['tmp_name'] = $_FILES['image_name']['tmp_name'][$i];
        $_FILES['file']['error'] = $_FILES['image_name']['error'][$i];
        $_FILES['file']['size'] = $_FILES['image_name']['size'][$i];

        $uploadPath = './uploads/blog/';
        $config['upload_path'] = $uploadPath;
        $config['allowed_types'] = 'jpg|jpeg|png|gif';
        $config['width'] = 200;
        $config['height'] = 250;

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

        if ($this->upload->do_upload('file')) {

            $imageData = $this->upload->data();

            $uploadImgData[] = $imageData['file_name'];
        }
    }
    $blogimage = $uploadImgData;
}

正如你可以看到我已经设置了高度和宽度在配置中,图片仍然上传在原来的大小,任何人都可以请告诉我什么是错的在这里,提前感谢

aij0ehis

aij0ehis1#

您刚刚在配置中犯了一个小错误:

$config['max_width'] = 200; 
$config['max_height'] = 250;

遗憾的是,“min_width”和“min_height”似乎还不存在

相关问题