2012-03-29 59 views
1
for($i=0;$i<count($status);$i++) 
{ 
    $conf = array(
     'source_image' => $status[$i]['full_path'], 
     'new_image' => $this->upload_path . '/thumbs', 
     'maintain_ratio' => true, 
     'width' => 200, 
     'height' => 200 
    ); 

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

    $this->image_lib->clear(); // complete reset  
    $this->image_lib->initialize($conf); // complete reset 
} 

      . 

始终保持缺少最后一个缩略图创建周期。当尝试($ i = 0; $ i < = count($ status); $ i ++)。我得到这个通知未定义偏移PHP/Codeigniter - For Loop [未定义偏移]

+0

当我保持状态小于$状态我想念的图像,当我把条件小于等于该脚本创建一个空白阵列。 – user1295342 2012-03-29 13:44:21

+0

你可以发布阵列的'var_dump'吗? – Ryan 2012-03-29 13:45:57

+0

你如何获得$状态? – Luciano 2012-03-29 13:47:12

回答

0

试试这个:

$this->load->library('image_lib'); 
$stat = array_values($status); 
for($i=0;$i<count($stat);$i++) 
{ 
$conf = array(
    'source_image' => $stat[$i]['full_path'], 
    'new_image' => $this->upload_path . '/thumbs', 
    'maintain_ratio' => true, 
    'width' => 200, 
    'height' => 200 
); 

$this->image_lib->initialize($conf); // complete reset 
$this->image_lib->resize(); 

} 
2

通过使用for循环你假设数组的键是连续的,这样他们可能没有。你还假设每个二级阵列都有一个full_path密钥,但它可能不是。使用foreach代替,并且做对full_path关键的isset()检查:

foreach ($status as $item) 
{ 

    if (!isset($item['full_path'])) continue; 

    $conf = array(
     'source_image' => $item['full_path'], 
     'new_image' => $this->upload_path . '/thumbs', 
     'maintain_ratio' => true, 
     'width' => 200, 
     'height' => 200 
    ); 

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

    $this->image_lib->clear(); // complete reset  
    $this->image_lib->initialize($conf); // complete reset 
}