PHP错误:未定义的偏移量:1 - LemonStand产品导出

时间:2017-08-02 18:04:27

标签: php

尝试在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);

1 个答案:

答案 0 :(得分:0)

$image_path不包含'|',因此在展开时,结果只包含1项(ofsset 0)和第2项(ofsset 1尝试存储在$file_name)中不存在。

因此,您的解决方案是确保$image_path包含必要的'|'或处理$image_path而不使用'|'