0

CIで複数の画像をアップロードしていますが、アップロードします。また、次のコードでサイズを変更しようとし
ています。最初の画像のみがサイズ変更され、残りは変更されません。それらは現在のサイズでアップロードされます。どうしたの?

どんな助けでも本当に、本当に感謝しています。

function doupload() {

    $path = array();
    $count = count($_FILES['userfile']['size']);

    foreach($_FILES as $key=>$value){
        for($n=0; $n<=$count-1; $n++) {
            $_FILES['userfile']['name']=$value['name'][$n];
            $_FILES['userfile']['type']    = $value['type'][$n];
            $_FILES['userfile']['tmp_name'] = $value['tmp_name'][$n];
            $_FILES['userfile']['error']       = $value['error'][$n];
            $_FILES['userfile']['size']    = $value['size'][$n];   

                $config['upload_path'] = './images';
                $config['allowed_types'] = 'gif|jpg|png|jpeg';

            $this->load->library('upload', $config);
            $this->upload->do_upload();
            $data = $this->upload->data();
            $path[] = $data['full_path']; //contains full path of every image
        }
    }   

    foreach($path as $p=>$ath){
        $config1 = array(
        'source_image'      => $ath,
        'new_image'         => './images',
        'maintain_ration'   => true,
        'overwrite'         => true, 
        'width'             => 600,
        'height'            => 400
        );

        $this->load->library('image_lib', $config1);            
        $this->image_lib->resize();
        $this->image_lib->clear();

    }


}
4

3 に答える 3

2

最初にループの外で image_lib をロードし、ループ内で初期化を使用して、すべてのイメージに新しい構成を渡すことができます

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

    foreach($path as $p=>$ath){
            $config1 = array(
            'source_image'      => $ath,
            'new_image'         => './images',
            'maintain_ration'   => true,
            'overwrite'         => true, 
            'width'             => 600,
            'height'            => 400
            );

            $this->image_lib->initialize($config);
            $this->image_lib->resize();
            $this->image_lib->clear();

        }
于 2012-10-10T08:17:25.157 に答える
0

CodeIgniter のLoaderクラスはライブラリを 1 回だけロードするためforeach、同じ画像のサイズを複数回変更します。ライブラリの読み込みをループの外に移動し、initializeImage Manipulation ライブラリの方法を使用して、サイズ変更ごとに構成を設定します。

于 2012-10-10T08:16:46.560 に答える
0

私の場合、コンストラクターでlibをロードし、コードを使用します

$config['image_library'] = 'gd2';
$config['maintain_ratio'] = FALSE;
$config['source_image'] = $config['upload_path'].$image_info['file_name'];

$config['new_image'] = $config['upload_path']."thumb_".$image_info['file_name'];
$config['width'] = 313;
$config['height'] = 303;
$this->image_lib->initialize($config); 
$this->image_lib->resize();
$this->image_lib->clear();

$config['new_image'] = $config['upload_path']."icon_".$image_info['file_name'];
$config['width'] = 70;
$config['height'] = 70;
$this->image_lib->initialize($config); 
$this->image_lib->resize();
$this->image_lib->clear();

インデックス名を常に new_image に保持する$config['new_image']

于 2014-05-14T19:59:31.607 に答える