2017-08-02 69 views
-1

我不斷收到試圖產品圖片導出LemonStand如果出現以下錯誤:PHP錯誤:未定義偏移:1 - LemonStand產品出口

Phpr_PhpException: Undefined offset: 1. In /public_html/store/modules/shop/classes/shop_productexport.php, line 158 

這裏是有問題的代碼:

// Images should be separated by newlines, and each should be in 
    // in {disk_name}|{real_name} format 
    protected static function get_images_for_export($row, $base_path = 'images', &$images_to_export = null) 
    { 
     if (empty($row['images'])) 
      return $row; 

     $image_paths = explode("\n", $row['images']); 
     $row['images'] = array(); 
     foreach ($image_paths as $image_path) 
     { 
      list($disk_name, $file_name) = explode('|', $image_path, 2); 
      $new_name = preg_replace('/[^\w_\.-]+/u', '_', $row['sku'].'-'.$file_name); 

      $row['images'][] = $base_path.'/'.$new_name; 
      $images_to_export[$disk_name] = $new_name; 
     } 

     $row['images'] = join(",", $row['images']); 
     return $row; 
    } 

線158是:

list($disk_name, $file_name) = explode('|', $image_path, 2); 

回答

0

$image_path不包含'|'所以爆炸時它僅包含1個項目(ofsset 0),而第二個項目(ofsset 1試圖存儲在$file_name中)不存在。

所以你的解決方案是要確保$image_path包含必要的'|'或處理$image_path的沒有'|'的不同。